Skip to content

fix(office): stop the layout destroying the URL on every deep link - #607

Merged
thinkclay merged 2 commits into
mainfrom
claude/kanban-final
Aug 12, 2026
Merged

thinkclay merged 2 commits into
mainfrom
claude/kanban-final

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

A real product bug, found while finally getting the office e2e suite to run.

Every shareable office URL silently degraded to /office

Measured by polling location.pathname through the load:

before: ["/office/applications", "/office"]   body still "Loading..."
after:  ["/office/applications"]              board renders

office/_layout.tsx returned early three times before its navigator — a Spinner while the role check resolved, and null when unauthorized or on a narrow viewport. Each of those unmounts the navigator, and expo-router responds by rewriting the URL to the nearest mounted segment.

So deep-linking to any office child lost its path. That includes the per-application detail route added in #537, whose entire purpose is being linkable — a recruiter sending a colleague a candidate URL would have landed them on /office.

Same failure class as the OAuth callback-hash loss fixed in #519, which is why (admin)/_layout.tsx already renders <Slot /> plus an overlay instead of returning around its navigator. This does the same: navigator always mounted, loading state layered on top, hooks keep doing their own redirects.

Two smaller fixes

applications/[applicationId]/index had no Stack.Screen entry — only its /inquiry sibling was registered, so the #537 route was missing from the list entirely. The comment above that list already documents this exact class of omission.

The super-admin auth setup wrote its session where the app could not read it. It used addInitScript, which runs on every origin — the session landed in the Stripe iframes (js.stripe.com, m.stripe.network) and never on localhost, so the saved state had no sb-*-auth-token for the app's own origin. It also wrote a wrapped { currentSession, expiresAt } payload where supabase-js stores the session flat. It now navigates then page.evaluates, matching the admin and user setups. All three storage states now carry a valid token on http://localhost:8081.

This settles #577

With the URL surviving, /office/applications renders all seven kanban columns with exactly the testIDs the helpers look for:

kanban-column-new, -screen, -inquired, -interview, -offer, -hired, -rejected

The selectors were never missing. @scaffald/ui has emitted them all along; the board had simply never rendered in a test. My original #577 diagnosis was wrong and I have corrected it there.

What is not verified here

I could not run the kanban spec to completion. Partway through this work the local supabase_db_scaffald container disappeared and pnpm supa start now fails at schema initialisation, so the app has no database. The evidence above was captured while the stack was still healthy — the URL sequences and the column list are real observations, not inferences — but the spec itself still needs a green run before any office spec goes into testMatch (#553).

CI has been unable to start jobs since ~00:28 UTC, so this carries local verification only: tsc --noEmit clean for both files, and the browser observations above.

Navigating to /office/applications landed on /office. Measured, not
inferred — polling location.pathname through the load gives:

  before: ["/office/applications", "/office"]   body still "Loading..."
  after:  ["/office/applications"]              board renders

office/_layout.tsx returned early three times before its navigator: a
Spinner while the role check resolved, and null when unauthorized or on a
narrow viewport. Each unmounts the navigator, and expo-router responds by
rewriting the URL to the nearest mounted segment. So every shareable office
URL silently degraded to /office — including the per-application detail
route added in #537, whose entire purpose is being linkable.

Same failure class as the OAuth callback-hash loss fixed in #519, which is
why (admin)/_layout.tsx already renders <Slot /> plus an overlay rather
than returning around its navigator. This does the same: the navigator
always mounts, the loading state is layered over it, and the hooks keep
doing their own redirects. It only stops the URL being destroyed while
they decide.

Also registers applications/[applicationId]/index as a Stack.Screen. Only
its /inquiry sibling was listed, so the #537 route had no entry at all —
the same class of omission the comment above that list already describes.

And the super-admin auth setup now writes its session the way the admin and
user setups do: navigate, then page.evaluate. It used addInitScript, which
runs on every origin — the session landed in the Stripe iframes
(js.stripe.com, m.stripe.network) and never on localhost, so the saved
state had no sb-*-auth-token for the app's own origin. It also wrote a
wrapped { currentSession, expiresAt } payload where supabase-js stores the
session flat. All three storage states now carry a valid token on
http://localhost:8081.

Verified against a running app: /office/applications keeps its URL and
renders all seven kanban columns with the testIDs the helpers look for —
kanban-column-new/screen/inquired/interview/offer/hired/rejected. That
also settles #577: the selectors were never missing, the board had simply
never rendered.
GET /v1/employer/applications authorised the caller against the
organisation and then read the rows through RLS, which decides on a
different axis. core.applications' policies recognise the organisation
*owner*; a user holding an org `admin` role assignment — exactly who
PIPELINE_ROLES exists to admit — passed authorisation and then read zero
rows.

Measured on the same 12 applications in one organisation:

  clay  (owner)            12 visible
  zach  (org admin)         0 visible
  GET /v1/employer/applications, as zach: total=0

The office kanban board rendered "0 total applications" for them. The
board was not broken; the list was returning an empty set to an authorised
user.

The read now uses the service-role client, after the existing
authorisation, exactly as attachStageHistory in this file and the EEO and
scheduling routes already do for the same reason (#544).

Verified after the change:

  clay  (owner)                    total=12
  zach  (org admin)                total=12   <- was 0
  brian (admin of another org)     total=3, only his own org's

Cross-organisation isolation is unchanged: the authorisation step still
bounds every query to listAccessibleOrganizationIds, and an admin of one
organisation sees exactly that organisation's applications and no others.

This is the fourth place the org-vs-team RLS mismatch has forced a
service-role read. #544 remains the real fix.
@thinkclay

Copy link
Copy Markdown
Contributor Author

Added a second commit, and it is the bigger of the two: fix(api): the employer pipeline was empty for everyone but the org owner.

The board was not broken — the API was returning an empty list to an authorised user

GET /v1/employer/applications authorises the caller against the organisation, then read the rows through RLS, which decides on a different axis. core.applications' policies recognise the organisation owner; a user holding an org admin role assignment — exactly who PIPELINE_ROLES exists to admit — passed authorisation and then read zero rows.

Measured on the same 12 applications in one organisation:

user rows visible under RLS GET /v1/employer/applications
clay — org owner 12 total=12
zach — org admin 0 total=0

That is why the kanban board rendered "0 total applications". I found it because the board finally rendered (first commit) and was still empty.

The read now uses the service-role client after the existing authorisation — the same escape hatch, for the same reason, that attachStageHistory in this file and the EEO and scheduling routes already use. After the change:

clay  (owner)                 total=12
zach  (org admin)             total=12   <- was 0
brian (admin of another org)  total=3, only his own org's

Cross-organisation isolation is unchanged: authorisation still bounds every query to listAccessibleOrganizationIds.

This is the fourth place the org-vs-team RLS mismatch has forced a service-role read. #544 is the real fix; this is the fourth patch over it.

Where the kanban spec got to

It now runs. Before this branch, all 20 tests died in the same beforeEach at waitForKanbanLoad. Now 3–5 pass and the rest fail on their own assertions.

I could not get a clean full run: the Expo dev server dies partway through, and 11 of the 20 failures in the last attempt were ERR_CONNECTION_REFUSED rather than assertions. Of the genuine ones, at least one is a spec-vs-implementation drift I can name — the spec asserts the page contains 'Rejected', but the board deliberately labels that column 'Closed', because #533 merged rejected and withdrawn into one terminal column with a badge.

So the spec still does not go into testMatch, and #553's sequencing holds. What changed is that the remaining work is now a short list of real assertions rather than "nothing runs at all".

@thinkclay
thinkclay merged commit 324af69 into main Aug 12, 2026
6 of 12 checks passed
@thinkclay
thinkclay deleted the claude/kanban-final branch August 12, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant