fix(clerk-js,ui): Preload component chunks in parallel during mount#7901
fix(clerk-js,ui): Preload component chunks in parallel during mount#7901jacekradko wants to merge 2 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: c5bd5b2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 |
|
!snapshot |
|
Hey @jacekradko - the snapshot version command generated the following package versions:
Tip: Use the snippet copy button below to quickly install the required packages. npm i @clerk/agent-toolkit@0.3.0-snapshot.v20260221025222 --save-exact
npm i @clerk/astro@3.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/backend@3.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/chrome-extension@3.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/clerk-js@6.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/dev-cli@1.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/expo@3.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/expo-passkeys@1.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/express@2.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/fastify@2.7.0-snapshot.v20260221025222 --save-exact
npm i @clerk/localizations@4.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/msw@0.0.1-snapshot.v20260221025222 --save-exact
npm i @clerk/nextjs@7.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/nuxt@2.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/react@6.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/react-router@3.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/shared@4.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/tanstack-react-start@1.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/testing@2.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/ui@1.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/upgrade@2.0.0-snapshot.v20260221025222 --save-exact
npm i @clerk/vue@2.0.0-snapshot.v20260221025222 --save-exact |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
📝 WalkthroughWalkthroughCalls to 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Replace the keepMounted Popover approach with chunk preloading. Pass preloadHint to ensureMounted() from all mount methods so component chunks download in parallel with the common chunk, eliminating the sequential waterfall on slow connections. Move preloadComponent() call outside the first-call guard so it fires on every ensureMounted() call.
9b06f86 to
cdc7d44
Compare
The __mocks__ directory in src/elements/ was not detected by Vitest for node_module mocks, so auto-animate ran in tests and leaked timers that fired after jsdom teardown, causing requestAnimationFrame errors.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/clerk-js/vitest.setup.mts`:
- Around line 265-270: Add unit tests that exercise the new preload/mount flow
and assert the component lifecycle now uses the explicit auto-animate mock:
write tests that simulate the preload step and then mount/render the component
and verify expected post-preload behavior (e.g., DOM state, callbacks invoked,
side effects) and that '@formkit/auto-animate/react' is mocked via
useAutoAnimate returning [null]; update or add tests in the clerk-js test suite
to cover both the preload->mount transition and that useAutoAnimate is not
causing timers or animations to run during teardown to prevent regressions.
| // Mock @formkit/auto-animate to prevent timers leaking after test teardown. | ||
| // The __mocks__ directory in src/elements/ is not detected by Vitest for | ||
| // node_module mocks, so we need an explicit vi.mock here. | ||
| vi.mock('@formkit/auto-animate/react', () => ({ | ||
| useAutoAnimate: () => [null], | ||
| })); |
There was a problem hiding this comment.
Add tests covering the behavioral change introduced in this PR.
No tests were added or updated to cover the new preload/mount behavior and the explicit auto-animate mock. Please add/adjust tests to validate the changed flow and guard against regressions.
As per coding guidelines “If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.”
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/clerk-js/vitest.setup.mts` around lines 265 - 270, Add unit tests
that exercise the new preload/mount flow and assert the component lifecycle now
uses the explicit auto-animate mock: write tests that simulate the preload step
and then mount/render the component and verify expected post-preload behavior
(e.g., DOM state, callbacks invoked, side effects) and that
'@formkit/auto-animate/react' is mocked via useAutoAnimate returning [null];
update or add tests in the clerk-js test suite to cover both the preload->mount
transition and that useAutoAnimate is not causing timers or animations to run
during teardown to prevent regressions.
Summary
mount*()calls, eliminating the sequential download waterfall that caused slow first-render on poor connectionspreloadHintfrom all 16mount*methods toensureMounted()so the component-specific chunk starts downloading immediately alongside the common chunkpreloadComponent()outside the first-call guard inensureMounted()so it fires on every call, not just the first — enabling preloading even when a different component was mounted firstkeepMountedPopover approach (hidden container rendering) in favor of this simpler chunk preloading strategyResolves USER-4747
Testing PR: https://github.com/clerk/dashboard/pull/8496
How it works
Before:
mount*()→ common chunk downloads → React renders →React.lazy()triggers component chunk download (sequential waterfall)After:
mount*()→ common chunk and component chunk download in parallel → React renders →React.lazy()finds module already loaded (no wait)preloadComponentis idempotent (returns a cached promise on repeat calls), so this is safe to call on everyensureMounted()invocation.Test plan
pnpm buildpassespnpm testpasses (1616 tests, 111 test files)git diff main --statshows only intended changes (2 files for preloading + 3 files reverting keepMounted)Summary by CodeRabbit