Skip to content

Scope demo route trees with createRootAtom instead of a rootAtom prop - #90

Open
randomdevpete wants to merge 2 commits into
masterfrom
task-679-investigate-per-demo-scoped-store-context
Open

Scope demo route trees with createRootAtom instead of a rootAtom prop#90
randomdevpete wants to merge 2 commits into
masterfrom
task-679-investigate-per-demo-scoped-store-context

Conversation

@randomdevpete

Copy link
Copy Markdown
Owner

Finding

Investigated scoping a demo's locationAtom to a path prefix via a jotai store context, so demos could declare route atoms as plain static values instead of a rootAtom prop + createXRoutes(root) factory. Not feasible with a store context, for two independent reasons (written up in packages/jarl-atoms/DESIGN-NOTES.md):

  • A nested <Provider store={createStore()}> doesn't inherit from its parent — the subtree gets its own atomWithLocation, which only refreshes on popstate. In-subtree navigation calls history.pushState, which fires no popstate, so the outer store goes stale: the URL changes but every route atom outside the subtree still matches the old location.
  • A store that shares state with its parent but overrides just locationAtom requires jotai 2.20's private, revision-numbered INTERNAL_buildStoreRev3 API (what jotai-scope is built on) — the public unstable_derive route is gone in this version. Not something a router should depend on.

createRootAtom({ basePath }) already gets the useful half of the idea in one store: route atoms below it are static module-level values, and the prefix is named once, on the root, where reverse() can prepend it again.

Change

  • DataGridApp and BlogRoutingApp now call createRootAtom({ basePath: "/demos/..." }) at module scope and declare their route atoms as plain static values — no more rootAtom prop, no createXRoutes factory, no per-instance useMemo.
  • Changelog was the one other place still on the old prop-passing pattern (same shape, one param route under a static mount). Migrated it too, since it's the same small change and leaves no straggler.
  • Two stale comments in routes.ts corrected to describe the new mounting scheme.
  • packages/jarl-atoms/DESIGN-NOTES.md — the project's existing home for recording rejected designs (predates this diff, already held similar entries from the v2 atoms core work) — gets a new section for this investigation.

Style-guide exceptions

None.

…om, dropping the rootAtom prop

Both demos declare their route atoms as plain module-level values under a
basePath-scoped root, so no factory, prop or memoisation stands between the
reader and the atom chain.

Ticket: 679
@randomdevpete
randomdevpete force-pushed the task-679-investigate-per-demo-scoped-store-context branch from a79fcfc to 8097ade Compare August 19, 2026 00:41
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