Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fd7bb98
WIP: Routing url modes
Ephem Nov 12, 2026
ea5b2fb
Fix swingset
Ephem Nov 12, 2026
b143a36
Listen to currententrychange
Ephem Nov 17, 2026
bf5f0cd
Fix tabs bug
Ephem Nov 17, 2026
bd6f402
Doc tweaks
Ephem Nov 17, 2026
45e5442
Update swingset routing demo
Ephem Nov 17, 2026
eab753d
Change query/hash mode prefix to be just . by default
Ephem Nov 17, 2026
b8b3e1b
Don't try to patch history state to recover behavior when no adapter …
Ephem Nov 23, 2026
5c5c129
Don't apply writes until page has settled
Ephem Nov 23, 2026
97057cb
Make hash ssr-safe
Ephem Nov 23, 2026
28ef480
Stop supporting path mode for modals and minor fixes
Ephem Nov 23, 2026
02b9827
Close modals on pathname change
Ephem Nov 24, 2026
a7d461a
Use URLSearchParams instead of custom decoding
Ephem Nov 24, 2026
321ead1
Fix self-review feedback
Ephem Nov 24, 2026
1fce2bb
Rename RouterAdapterProvider -> RoutingConfigProvider
Ephem Nov 24, 2026
2b83839
Fix swingset
Ephem Nov 24, 2026
dc01744
More cleanup
Ephem Nov 24, 2026
6926a20
Bump bundlewatch
Ephem Nov 24, 2026
a1b78e2
Rename some types away from Mosaic
Ephem Nov 24, 2026
d9c1d5d
More cleanup
Ephem Nov 25, 2026
30cef3c
Be consistent about calling base+parts a segment
Ephem Nov 25, 2026
c48d7ab
Rename UrlCarrier -> SegmentCodec
Ephem Nov 25, 2026
2966c3d
Add readUrl to the router adapter interface
Ephem Nov 25, 2026
46a8657
Inline useUrlModeLocation creation
Ephem Nov 25, 2026
3e2f193
Make router work without window
Ephem Nov 25, 2026
92c86cc
Freeze push, replace and readUrl to first ones provided
Ephem Nov 25, 2026
2e6fc43
Update changeset
Ephem Nov 25, 2026
ff12265
Close hash and query modals on pathname change
Ephem Nov 25, 2026
06575ed
Fix test bugs and hash mode timing issue
Ephem Nov 25, 2026
b94fb7b
Read the modal host's pathname from the segment's source
Ephem Nov 25, 2026
4869a44
Pin vite to 8.3.8 in the Nuxt integration template
Ephem Nov 26, 2026
e3763d0
Say why vite is pinned in the Nuxt template
Ephem Nov 26, 2026
df02ece
Pin vite for npm installs of the Nuxt template too
Ephem Nov 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/mosaic-url-routing-modes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@clerk/mosaic': minor
---

Adds 'path', 'query' and 'hash' routing modes.

`UserProfile`, `OrganizationProfile` and `Profile` take a `routing` prop that keeps the open page in the pathname under `path`, in a query param, or in the hash, so the page survives a reload and Back returns to the previous one. `virtual`, in memory, stays the default.

`MosaicProvider` takes a `routing` prop. `adapter` connects the URL modes to the host router (`usePathname` and `useSearchParams` from `next/navigation` is the Next.js one), `modals: 'query' | 'hash'` puts the profile modals in the URL too, and `keyPrefix` sets what the param names start with.

Modals now close when the host navigates to another pathname.
3 changes: 3 additions & 0 deletions integration/templates/nuxt-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"postinstall": "nuxt prepare",
"preview": "nuxt preview --port $PORT"
},
"overrides": {
"vite": "8.3.8"
},
"dependencies": {
"nuxt": "4.5.1",
"vue": "^3.5.30",
Expand Down
10 changes: 10 additions & 0 deletions integration/templates/nuxt-node/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
packages:
- '.'

# Vite 8.4.0 (2026-11-26) moved to rolldown 1.3 and Nuxt 4.5.1's build fails under it with
# EXTERNAL_MODULES_CANNOT_BE_TRANSFORMED_TO_MODULES on unctx. The temp app installs fresh, so
# its transitive vite floated onto it. The harness installs the app with npm through pkglab,
# which reads the top-level "overrides" in package.json; this file covers a pnpm install.
# Drop both pins once Nuxt or Vite ships a fix.
overrides:
vite: 8.3.8
2 changes: 1 addition & 1 deletion packages/mosaic/bundlewatch.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": [
{ "path": "./dist/.bundlewatch/eager/index.js", "maxSize": "28KB" },
{ "path": "./dist/.bundlewatch/total/index.js", "maxSize": "315KB" },
{ "path": "./dist/.bundlewatch/total/index.js", "maxSize": "316KB" },
{ "path": "./dist/styles.css", "maxSize": "19KB" }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function OrganizationProfileModalContent({
options,
close,
path,
routing,
}: OrganizationProfileModalContentProps): React.ReactElement {
const { isLoaded, organization } = useOrganization();
const inactive = isLoaded && !organization;
Expand All @@ -23,6 +24,7 @@ export default function OrganizationProfileModalContent({
<OrganizationProfile
{...props}
path={path}
routing={routing}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import type { ReactNode } from 'react';

import type { RoutingMode } from '../../routing/use-mosaic-location';
import type { APIKeysPageProps } from '../api-keys/api-keys-table';
import { Profile } from '../profile/profile';
import type { OrganizationProfileOptions } from './organization-profile.provider';
Expand All @@ -18,6 +19,13 @@ export interface OrganizationProfileProps
* @default '/organization'
*/
path?: string;
/**
* Where the profile keeps the page that is open. `virtual` keeps it in memory, so the URL does not
* change. `path` puts it in the URL's pathname, `query` and `hash` in a param of the query string or the hash.
*
* @default 'virtual'
*/
routing?: RoutingMode;
/**
* Rendered while Clerk is loading. Nothing renders once the answer is that there is no active
* organization.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest';
import { logger } from '@clerk/shared/logger';
import { afterEach, describe, expect, it, vi } from 'vitest';

import { pageParts, pageSegment } from '../profile-pages.layout';
import { pageParts, pageSegment, withRoutablePaths } from '../profile-pages.layout';

describe('pageSegment', () => {
it('maps the built-in ids to the segments legacy used', () => {
Expand All @@ -14,6 +15,12 @@ describe('pageSegment', () => {
expect(pageSegment('usage')).toBe('usage');
expect(pageSegment('docs/apiKeys')).toBe('docs/apiKeys');
});

it('leaves an id named after an Object.prototype property as it is', () => {
for (const id of ['constructor', 'toString', '__proto__', 'hasOwnProperty', 'valueOf']) {
expect(pageSegment(id)).toBe(id);
}
});
});

describe('pageParts', () => {
Expand All @@ -24,3 +31,26 @@ describe('pageParts', () => {
expect(pageParts('/usage/')).toEqual(['usage']);
});
});

describe('withRoutablePaths', () => {
afterEach(() => vi.restoreAllMocks());

it('keeps a page whose path is an Object.prototype property', () => {
const warn = vi.spyOn(logger, 'warnOnce').mockImplementation(() => {});
const pages = [{ path: 'toString' }, { path: 'constructor' }, { path: '__proto__' }];
expect(withRoutablePaths(pages, ['account', 'apiKeys']).map(page => page.path)).toEqual([
'toString',
'constructor',
'__proto__',
]);
expect(warn).not.toHaveBeenCalled();
});

it('leaves out a page whose path has a . or .. part, which a URL resolves away', () => {
const warn = vi.spyOn(logger, 'warnOnce').mockImplementation(() => {});
const pages = [{ path: 'usage' }, { path: '..' }, { path: 'docs/.' }];
expect(withRoutablePaths(pages, []).map(page => page.path)).toEqual(['usage']);
expect(warn).toHaveBeenCalledTimes(2);
expect(warn).toHaveBeenCalledWith(expect.stringContaining('".." has a "." or ".." part'));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const BUILT_IN_SEGMENTS: Readonly<Record<string, string>> = {
};

export function pageSegment(id: string): string {
return BUILT_IN_SEGMENTS[id] ?? id;
const segment = Object.hasOwn(BUILT_IN_SEGMENTS, id) ? BUILT_IN_SEGMENTS[id] : undefined;
return segment ?? id;
}

export function pageParts(page: string | undefined): string[] {
Expand Down Expand Up @@ -44,6 +45,12 @@ export function withRoutablePaths<Page extends { path: string }>(
logger.warnOnce(`[Clerk] Custom page path "${page.path}" cannot start with a colon, so the page is left out.`);
return false;
}
if (parts.some(part => part === '.' || part === '..')) {
logger.warnOnce(
`[Clerk] Custom page path "${page.path}" has a "." or ".." part, which a URL resolves away, so the page is left out.`,
);
return false;
}
if (parts.some(part => part.includes('%'))) {
logger.warnOnce(
`[Clerk] Custom page path "${page.path}" contains percent-encoding, so the page is left out. Write it as plain text.`,
Expand Down
12 changes: 8 additions & 4 deletions packages/mosaic/src/features/profile-pages/use-mosaic-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ export interface MosaicProfile {
*/
combined?: boolean;
/**
* Options for the user profile, whichever component opens or mounts it.
* Options for the user profile, whichever component opens or mounts it. `routing` and `path`
* apply when the profile is mounted on a page, they are ignored for the modal version.
*/
userProfileProps?: ProfileUserProps;
/**
* Options for the organization profile, or the organization's pages in a combined profile,
* whichever component opens or mounts it.
* whichever component opens or mounts it. `routing` and `path` apply when the profile is mounted
* on a page, they are ignored for the modal version.
*/
organizationProfileProps?: ProfileOrganizationProps;
/**
Expand Down Expand Up @@ -54,13 +56,15 @@ export interface ProfilePages<PageId extends string> {

/** Options for the underlying `<UserProfile />` component. */
export interface ProfileUserProps
extends ProfilePages<UserProfilePageId>, Pick<UserProfileProps, 'additionalOAuthScopes' | 'apiKeysProps' | 'path'> {}
extends
ProfilePages<UserProfilePageId>,
Pick<UserProfileProps, 'additionalOAuthScopes' | 'apiKeysProps' | 'path' | 'routing'> {}

/** Options for the underlying `<OrganizationProfile />` component. */
export interface ProfileOrganizationProps
extends
ProfilePages<OrganizationProfilePageId>,
Pick<OrganizationProfileProps, 'afterLeaveOrganizationUrl' | 'apiKeysProps' | 'path'> {}
Pick<OrganizationProfileProps, 'afterLeaveOrganizationUrl' | 'apiKeysProps' | 'path' | 'routing'> {}

const MosaicProfileContext = createContext<MosaicProfile>({});

Expand Down
12 changes: 11 additions & 1 deletion packages/mosaic/src/features/profile/profile.modal-content.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import { useUser } from '@clerk/shared/react';
import React from 'react';

import type { RoutingMode } from '../../routing/use-mosaic-location';
import { profileModalOptions, useMosaicProfile } from '../profile-pages/use-mosaic-profile';
import { UserProfileSurface } from './profile';
import type { ProfileModalContentProps, ProfileModalOptions } from './profile.modal.types';

export default function ProfileModalContent({ options, close, path }: ProfileModalContentProps): React.ReactElement {
export default function ProfileModalContent({
options,
close,
path,
routing,
}: ProfileModalContentProps): React.ReactElement {
const profile = useMosaicProfile();
return (
<ModalProfile
options={options ?? profileModalOptions(profile)}
close={close}
path={path}
routing={routing}
combined
/>
);
Expand All @@ -21,11 +28,13 @@ export function ModalProfile({
options: { page: _page, ...props },
close,
path,
routing,
combined,
}: {
options: ProfileModalOptions;
close: () => void;
path: string;
routing: RoutingMode;
combined: boolean;
}): React.ReactElement {
const { isLoaded, user } = useUser();
Expand All @@ -43,6 +52,7 @@ export function ModalProfile({
combined={combined}
presentation='modal'
path={path}
routing={routing}
/>
);
}
27 changes: 20 additions & 7 deletions packages/mosaic/src/features/profile/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import type { ReactNode } from 'react';

import type { RoutingMode } from '../../routing/use-mosaic-location';
import type { APIKeysPageProps } from '../api-keys/api-keys-table';
import type { OrganizationProfileProps } from '../organization-profile/organization-profile';
import { organizationProfilePageIds } from '../organization-profile/organization-profile.layout';
Expand Down Expand Up @@ -89,8 +90,10 @@ export function Profile(props: ProfileProps): ReactNode {
if (props.mode === 'organization') {
return (
<OrganizationProfileSurface
key={props.routing ?? provider.organizationProfileProps?.routing}
{...withOrganizationDefaults(props, provider.organizationProfileProps)}
path={props.path ?? provider.organizationProfileProps?.path}
routing={props.routing ?? provider.organizationProfileProps?.routing}
/>
);
}
Expand Down Expand Up @@ -125,7 +128,7 @@ function withUserDefaults(
props: UserProfileProps,
defaults: Pick<
UserProfileProps,
'customPages' | 'pageOrder' | 'additionalOAuthScopes' | 'apiKeysProps' | 'path'
'customPages' | 'pageOrder' | 'additionalOAuthScopes' | 'apiKeysProps' | 'path' | 'routing'
> = {},
): UserProfileProps {
const {
Expand All @@ -134,9 +137,10 @@ function withUserDefaults(
additionalOAuthScopes = defaults.additionalOAuthScopes,
apiKeysProps = defaults.apiKeysProps,
path = defaults.path,
routing = defaults.routing,
fallback,
} = props;
return { customPages, pageOrder, additionalOAuthScopes, apiKeysProps, path, fallback };
return { customPages, pageOrder, additionalOAuthScopes, apiKeysProps, path, routing, fallback };
}

function withOrganizationDefaults<Props extends NonNullable<CombinedProfileProps['organizationProfileProps']>>(
Expand All @@ -159,6 +163,7 @@ export function UserProfileSurface({
customPages,
pageOrder,
path = '/user',
routing = 'virtual',
additionalOAuthScopes,
fallback,
apiKeysProps: { hide: hideAPIKeys = false, ...apiKeysProps } = {},
Expand All @@ -176,6 +181,7 @@ export function UserProfileSurface({
const viewProps: AccountViewProps = {
elevation: 'flush',
path,
routing,
customPages,
pageOrder,
pages: {
Expand All @@ -194,24 +200,29 @@ export function UserProfileSurface({
>
{combined ? (
<CombinedUserProfileView
key={routing}
{...viewProps}
organizationProfileProps={organizationProfileProps}
fallback={fallback}
/>
) : (
<AccountUserProfileView {...viewProps} />
<AccountUserProfileView
key={routing}
{...viewProps}
/>
)}
</UserProfileProvider>
);
}

type AccountViewProps = Omit<UserProfileViewProps, 'activePage' | 'onPageChange' | 'organization'> & {
path: string;
routing: RoutingMode;
};

function AccountUserProfileView({ path, ...viewProps }: AccountViewProps) {
function AccountUserProfileView({ path, routing, ...viewProps }: AccountViewProps) {
const { activePage, onPageChange } = useProfilePagesController(userProfilePageIds(viewProps), {
routing: 'virtual',
routing,
path,
});

Expand All @@ -230,6 +241,7 @@ function AccountUserProfileView({ path, ...viewProps }: AccountViewProps) {

function CombinedUserProfileView({
path,
routing,
fallback,
organizationProfileProps: { customPages, pageOrder, apiKeysProps, afterLeaveOrganizationUrl } = {},
...viewProps
Expand All @@ -241,7 +253,7 @@ function CombinedUserProfileView({
: undefined;
const pageIds = model.status === 'loading' ? undefined : userProfilePageIds({ ...viewProps, organization });
const { activePage, onPageChange } = useProfilePagesController(pageIds, {
routing: 'virtual',
routing,
path,
notFound: parts =>
`${parts[0]}/` === ORGANIZATION_PAGE_PREFIX
Expand Down Expand Up @@ -269,6 +281,7 @@ export function OrganizationProfileSurface({
customPages,
pageOrder,
path = '/organization',
routing = 'virtual',
afterLeaveOrganizationUrl,
fallback,
apiKeysProps,
Expand All @@ -277,7 +290,7 @@ export function OrganizationProfileSurface({
const pages = model.status === 'ready' ? organizationProfilePanels(model.pages, apiKeysProps) : undefined;
const { activePage, onPageChange } = useProfilePagesController(
pages && organizationProfilePageIds({ pages, customPages, pageOrder }),
{ routing: 'virtual', path },
{ routing, path },
);

if (model.status === 'loading') {
Expand Down
Loading
Loading