Skip to content

chore(clerk-js,ui): upgrade to Rspack 2#8382

Open
jacekradko wants to merge 8 commits into
mainfrom
jacek/rspack-2
Open

chore(clerk-js,ui): upgrade to Rspack 2#8382
jacekradko wants to merge 8 commits into
mainfrom
jacek/rspack-2

Conversation

@jacekradko

@jacekradko jacekradko commented Apr 22, 2026

Copy link
Copy Markdown
Member

Upgrades @clerk/clerk-js and @clerk/ui bundling from Rspack 1.7.x to Rspack 2 (2.0.6). Every variant builds (7 for clerk-js, 3 for ui), and the unit + integration matrix and bundlewatch are all green. Node minimum moves to 22.12.0, a Rspack 2 requirement.

The part worth real scrutiny is the config migration in packages/clerk-js/rspack.config.mjs and packages/ui/rspack.config.js: the config moves to ESM (Rspack 2 core is pure ESM), output.libraryTarget: 'x' is rewritten to output.library: { type: 'x' } across both configs, and experiments.cache graduates to a top-level cache. Since clerk-js/ui load into apps pinned on older SDK versions, the thing to confirm is that the per-variant bundle shape (library type, chunking) is unchanged.

Two small riders come along: bundlewatch budgets nudged up for Rspack 2's marginally larger gzip (clerk.browser.js 70→72KB, base-account-sdk 203→205KB, otherwise within ~0.1KB), and two @clerk/shared typecheck fixes, dropping the now-built-in NoInfer import from @tanstack/query-core and guarding script.nonce in loadScript.ts (matching #8177).

Holding the merge while the TS 6.0 work (#8177) settles, since the two overlap in the bundlewatch config and @clerk/ui's build.

Bumps the Rspack catalog to 2.0.0 and applies the migration:
- Node minimum bumped to 22.12.0 (Rspack 2 requirement)
- Convert clerk-js rspack.config.js to .mjs (Rspack 2 core is pure ESM)
- Rename output.libraryTarget to output.library.type (8 sites)
- Move experiments.cache to top-level cache
- Drop --analyze CLI flag (removed in v2; Rsdoctor remains for analysis)
- Bump @rsdoctor/rspack-plugin to 1.5.x
- Add @rspack/dev-server as a direct dep (no longer bundled with @rspack/cli)

Both packages build green across all variants.
@vercel

vercel Bot commented Apr 22, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Jun 4, 2026 8:42pm

Request Review

@changeset-bot

changeset-bot Bot commented Apr 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 94cc5fb

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

This PR includes changesets to release 4 packages
Name Type
@clerk/clerk-js Patch
@clerk/ui Patch
@clerk/chrome-extension Patch
@clerk/expo 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

@jacekradko jacekradko marked this pull request as ready for review April 22, 2026 21:50
@pkg-pr-new

pkg-pr-new Bot commented Apr 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8382

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8382

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8382

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8382

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8382

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8382

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8382

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8382

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8382

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8382

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8382

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8382

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8382

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8382

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8382

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8382

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8382

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8382

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8382

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8382

commit: 94cc5fb

@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR upgrades the Rspack build tooling to v2 across clerk-js and ui: migrating clerk-js rspack config to ESM imports/exports, replacing deprecated libraryTarget with library: { type: ... } for all outputs, consolidating dev cache configuration to cache: { type: 'memory' }, and updating npm scripts to reference rspack.config.mjs. DevDependencies related to Rspack are bumped/added. Additional edits adjust bundlewatch size and apply two small shared changes (conditional script.nonce assignment and a narrowed type import). Workspace pnpm catalogs and a trustPolicy exclusion were updated.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'chore(clerk-js,ui): upgrade to Rspack 2' is concise and clearly summarizes the main change: a Rspack 2 upgrade for clerk-js and ui packages.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description clearly relates to the changeset. It explains the Rspack 1.7.x to 2.x upgrade for @clerk/clerk-js and @clerk/ui, mentions config migrations, bundle size adjustments, and typecheck fixes, all of which align with the files changed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/clerk-js/rspack.config.mjs (1)

2-518: ⚠️ Potential issue | 🟠 Major

Merge blocker: no test coverage/verification for a build-system migration

This PR changes core bundling behavior (Rspack major version, config format, output library config, cache semantics) but includes no added/updated tests or automated verification in the change set. Please add and run migration-focused build/test coverage (at least smoke coverage across the declared variants) before merge.

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/rspack.config.mjs` around lines 2 - 518, The PR introduces
a major rspack-based bundling change but lacks migration/verification tests; add
automated smoke tests that build and validate each declared variant (use
variants object keys and entryForVariant, prodConfig and devConfig outputs) to
CI: create test scripts that invoke the rspack build for clerkBrowser,
clerkLegacyBrowser, clerkNative, clerk (ESM/CJS) and clerkNoRHC variants, assert
successful exit and presence of expected output files (check
output.filename/library type for commonjs/module/umd and chunking behavior), and
add these tests to the repository CI pipeline so they run on PRs before merge.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.changeset/rspack-2-upgrade.md:
- Line 6: Add a CI-backed smoke test that verifies the Rspack 2 build/runtime
produces working bundles for the changed packages (`@clerk/clerk-js` and
`@clerk/ui`): create a new lightweight workflow or job (e.g.,
.github/workflows/smoke-rspack2.yml) that installs Node 22.12.0, runs the repo
build (npm/yarn build), runs a small script or test (e.g., a new script
"smoke:rspack2" in package.json) that imports the built bundles and asserts
basic runtime behavior (bundle loads without runtime errors and exports expected
symbols), and fail the job on any error; ensure the workflow runs on PRs and
include the new smoke script and any minimal test file under test/smoke or
tests/smoke so the CI actually exercises the new Rspack 2 output before merging.

In `@pnpm-workspace.yaml`:
- Around line 50-51: The exception currently whitelists the entire scope token
'@rspack/*', which is too broad; replace that entry with explicit
package+version pins for only the four newly added 2.0.0 packages (e.g.,
'@rspack/package-name@2.0.0') so only those exact artifacts bypass the 48h gate,
and keep the existing TODO comment about removing the pins once 2.0.0 is older
than 48h.

---

Outside diff comments:
In `@packages/clerk-js/rspack.config.mjs`:
- Around line 2-518: The PR introduces a major rspack-based bundling change but
lacks migration/verification tests; add automated smoke tests that build and
validate each declared variant (use variants object keys and entryForVariant,
prodConfig and devConfig outputs) to CI: create test scripts that invoke the
rspack build for clerkBrowser, clerkLegacyBrowser, clerkNative, clerk (ESM/CJS)
and clerkNoRHC variants, assert successful exit and presence of expected output
files (check output.filename/library type for commonjs/module/umd and chunking
behavior), and add these tests to the repository CI pipeline so they run on PRs
before merge.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 28eb5570-4ee1-4362-ae85-fc2dc0f1f50b

📥 Commits

Reviewing files that changed from the base of the PR and between 8a25c6a and 0b488fe.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • .changeset/rspack-2-upgrade.md
  • .nvmrc
  • package.json
  • packages/clerk-js/package.json
  • packages/clerk-js/rspack.config.mjs
  • packages/clerk-js/turbo.json
  • packages/ui/package.json
  • packages/ui/rspack.config.js
  • pnpm-workspace.yaml

Comment thread .changeset/rspack-2-upgrade.md
Comment thread pnpm-workspace.yaml Outdated
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Break Check: no API changes detected across the tracked packages.

Last ran on 94cc5fb. Pushes that change no tracked declarations (no API surface change vs. base) are skipped and don't update this comment.

Drop the NoInfer import from @tanstack/query-core (removed in 5.100.14;
TS provides NoInfer as a built-in) and guard the script.nonce assignment
for stricter typecheck, matching #8177. Bump clerk.browser.js and
base-account-sdk bundlewatch budgets for rspack 2's slightly larger gzip output.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/shared/src/react/query/useQuery.ts (1)

36-41: ⚡ Quick win

Add JSDoc documentation for the public API function.

The useClerkQuery function is exported and part of the public API, but currently has an empty JSDoc comment. As per coding guidelines, public APIs should be documented with @param, @returns, and @example tags.

📝 Suggested JSDoc documentation
 /**
- *
+ * Hook to execute a Clerk-specific query using TanStack Query patterns.
+ *
+ * `@param` options - Query configuration options including queryKey, queryFn, and other TanStack Query options
+ * `@returns` Query result with data, error, loading, and fetching states
+ *
+ * `@example`
+ * ```tsx
+ * const { data, error, isLoading } = useClerkQuery({
+ *   queryKey: ['user', userId],
+ *   queryFn: () => fetchUserData(userId),
+ *   enabled: !!userId,
+ * });
+ * ```
  */
 export function useClerkQuery(options: UseQueryOptions) {
   return useBaseQuery(options, QueryObserver);
 }

As per coding guidelines: "All public APIs must be documented with JSDoc".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/shared/src/react/query/useQuery.ts` around lines 36 - 41, Add a
proper JSDoc block above the exported function useClerkQuery describing its
purpose, a `@param` for the options parameter (type UseQueryOptions), a `@returns`
describing the query result shape, and an `@example` showing typical usage (e.g.,
queryKey, queryFn, enabled). Reference the implementation details by mentioning
useBaseQuery and QueryObserver so the docs note that useClerkQuery delegates to
useBaseQuery(options, QueryObserver). Keep the comment concise and follow
existing project JSDoc style.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/shared/src/react/query/useQuery.ts`:
- Around line 36-41: Add a proper JSDoc block above the exported function
useClerkQuery describing its purpose, a `@param` for the options parameter (type
UseQueryOptions), a `@returns` describing the query result shape, and an `@example`
showing typical usage (e.g., queryKey, queryFn, enabled). Reference the
implementation details by mentioning useBaseQuery and QueryObserver so the docs
note that useClerkQuery delegates to useBaseQuery(options, QueryObserver). Keep
the comment concise and follow existing project JSDoc style.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: eed67afe-f65b-45d3-b58c-ec5a0a59ad5e

📥 Commits

Reviewing files that changed from the base of the PR and between 8fd4764 and 71991d7.

📒 Files selected for processing (3)
  • packages/clerk-js/bundlewatch.config.json
  • packages/shared/src/loadScript.ts
  • packages/shared/src/react/query/useQuery.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/clerk-js/bundlewatch.config.json

Bump @rspack/core and @rspack/cli to 2.0.6, @rspack/dev-server to 2.0.3,
and @rspack/plugin-react-refresh to 2.0.1 (each package's latest in the
2.0.x line). All four are now >48h old, so drop the temporary @rspack/*
entry from minimumReleaseAgeExclude, restoring the release-age quarantine.
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.

2 participants