Skip to content

feat(mosaic): open legacy hash URLs in path and hash routing - #11129

Draft
austincalvelage wants to merge 8 commits into
austin/mosaic-sign-up-url-routingfrom
austin/mosaic-path-routing-legacy-hash
Draft

austincalvelage wants to merge 8 commits into
austin/mosaic-sign-up-url-routingfrom
austin/mosaic-path-routing-legacy-hash

Conversation

@austincalvelage

Copy link
Copy Markdown
Member

Description

Makes path- and hash-routed Mosaic components open legacy hash URLs (#/continue?…) the way @clerk/ui's routers do. Stacked on #11128.

Clerk builds a component URL with the page in the hash: redirectToSignUp(), buildSignUpUrl(), the One Tap and OAuth callbacks in clerk-js, and the previous PR's virtual-mode return, <signUpUrl>#/sso-callback?…. ui's PathRouter moves that hash into the path before routing, and its HashRouter routes on it directly. Mosaic did neither, so a Mosaic page at the sign-up URL ignored the route and the redirect params.

Shared changes (for Mosaic reviewers)

This changes useRouterScope, so every path- or hash-routed component gets it, including the exported UserProfile, OrganizationProfile and Profile. The changeset is a patch for @clerk/mosaic.

1. A legacy hash is moved into the component's own route before anything renders. When the window hash starts with #/, the scope replaces the URL through the host adapter's replace, or history.replaceState without one, and renders nothing until the URL has changed, as PathRouter returns null until it is stripped. Without the gate, sign-up would read its arrival from the old URL for a frame.

switch (routing) {
  case 'path':
    return urlWithFragmentMerged; // /sign-up#/continue?x=1 -> /sign-up/continue?x=1
  case 'hash': {
    const codec = createSegmentCodec('hash', path, { query: queryPrefix, hash: hashPrefix });
    return url => urlWithFragmentRouted(codec, url); // /app#/continue?x=1 -> /app?x=1#.sign-up=continue
  }
  case 'query':
  case 'virtual':
    return undefined; // ui has no query mode, and its virtual router reads no URL
}

Both use hasUrlInFragment and mergeFragmentIntoUrl from @clerk/shared, the helpers ui uses, so the hash's params override a query param of the same name as they do there. #section and Mosaic's own #.sign-up=… are left alone.

2. Sign-up reads what Clerk put in the hash. After the move, the redirect params are in the query, where sign-up reads them, so /sign-up#/?redirect_url=%2Fafter sends the user to /after. A virtual-routed sign-up's OAuth return to /sign-up#/sso-callback?… completes on a path-routed sign-up page at that URL.

Known gaps

  • Two hash-routed components on one page share one #/ hash. The first to convert takes the route.
  • On a server-rendered page the hash is readable only after hydration, so the component renders once before the gate takes over.
  • Sign-up does not read initial values from the query yet, as ui does with getInitialValuesFromQueryParams.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

🤖 Generated with Claude Code

@vercel

vercel Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
clerk-js-sandbox Ready Ready Preview Dec 4, 2026 11:34pm UTC
mosaic-docs Ready Ready Preview Dec 4, 2026 11:34pm UTC
swingset Ready Ready Preview Dec 4, 2026 11:34pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f5bcc70

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@clerk/mosaic Patch
@clerk/mosaic-docs Patch
@clerk/nextjs Patch
@clerk/swingset Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

This branch was successfully deployed

2 active deployments
Preview – swingset — f5bcc701 Deployed Dec 4, 2026 by vercel[bot]
Preview – clerk-js-sandbox — f5bcc701 Deployed Dec 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant