Skip to content

fix(app): use module-level slot for TitlebarRight to fix direct session URL crash - #45357

Closed
TomKalina wants to merge 1 commit into
anomalyco:v2from
TomKalina:fix/v2-titlebarright-provider
Closed

fix(app): use module-level slot for TitlebarRight to fix direct session URL crash#45357
TomKalina wants to merge 1 commit into
anomalyco:v2from
TomKalina:fix/v2-titlebarright-provider

Conversation

@TomKalina

Copy link
Copy Markdown

Summary

Direct navigation to /server/{key}/session/{id} routes crashes with:

Error: TitlebarRight must be used within TitlebarRightProvider

even though the provider is mounted. The error boundary catches it and shows "Something went wrong".

Root cause

SolidJS context propagation across lazy-loaded route chunks: the useContext lookup in TitlebarRight (session-header.tsx, in route chunk) fails to find the provider that lives in the main chunk (shell.tsx).

Verified via console logs in production build:

  • [Provider] mounted fires successfully in the main chunk
  • [Mount] has slotTitlebarRightMount (in shell.tsx, same chunk as Provider) sees the context
  • [useSlot] context lookup: MISSINGTitlebarRight (in lazy-loaded route-*.js chunk) cannot find the context

This is the same class of bug as #30898 ("ServerSync context must be used within a context provider"), which is still open.

In Vite dev mode (HMR) the bug does not reproduce — context propagation works correctly there.

Fix

Replace createContext/useContext with a module-level singleton slot. Both the provider and consumers reference the same module-level instance, sidesteping the cross-chunk context lookup entirely.

  • TitlebarRightProvider becomes a no-op wrapper (kept for backward compatibility / minimal diff)
  • createTitlebarRightSlot factory is preserved for the existing unit test
  • All other call sites (TitlebarRightMount, TitlebarRight) reference the module-level slot directly

Verification

Built opencode2 v2 binary from this branch, deployed, and tested:

  • ✅ Direct URL navigation to /server/{key}/session/{id} loads session content
  • ✅ Click from home page session list works
  • ✅ Back/forward browser navigation works
  • ✅ Newly created sessions display correctly (v1/v2 storage mismatch also resolved via PR refactor(app): remove V1 client compatibility #43045 in v2 branch)
$ curl -u opencode:**** http://127.0.0.1:4096/api/session/ses_.../message?limit=20 | jq '.data | length'
3

Diff

Single file change (packages/app/src/shell/titlebar/right-slot.tsx):

-const TitlebarRightContext = createContext<TitlebarRightSlot>()
+// Module-level singleton slot. The provider and consumers all reference this
+// instance, which sidesteps SolidJS context propagation issues across lazy-loaded
+// route chunks where useSlot would otherwise throw "must be used within
+// TitlebarRightProvider" even though the provider is mounted.
+const [slotStore, setSlotStore] = createStore<{ mount?: HTMLElement; registrations: symbol[] }>({
+  registrations: [],
+})
+
+const slot: TitlebarRightSlot = { ... }
 
 export function TitlebarRightProvider(props: ParentProps) {
-  return (
-    <TitlebarRightContext.Provider value={createTitlebarRightSlot()}>{props.children}</TitlebarRightContext.Provider>
-  )
+  return <>{props.children}</>
 }

Related

…on URL crash

Direct navigation to /server/{key}/session/{id} routes crashes with
'TitlebarRight must be used within TitlebarRightProvider' even though
the provider is mounted. Root cause is SolidJS context propagation
across lazy-loaded route chunks: the context lookup in TitlebarRight
(session-header.tsx, in route chunk) fails to find the provider that
lives in the main chunk (shell.tsx).

Replacing createContext/useContext with a module-level singleton slot
sidesteps the issue entirely. The provider becomes a no-op wrapper for
backward compatibility. createTitlebarRightSlot is preserved as a
factory for tests.

Verified:
- Direct URL to /server/{key}/session/{id} loads session content
- Click from home page works
- Back/forward navigation works
- Newly created sessions display correctly

Refs: anomalyco#30898 (similar 'ServerSync context' report)
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Aug 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 26, 2026
@github-actions github-actions Bot closed this Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant