Skip to content

fix(react-router): read VITE env-var for dev-warning suppression in SPA mode#8682

Merged
jacekradko merged 3 commits into
mainfrom
jacek/react-router-spa-disable-dev-warning
May 28, 2026
Merged

fix(react-router): read VITE env-var for dev-warning suppression in SPA mode#8682
jacekradko merged 3 commits into
mainfrom
jacek/react-router-spa-disable-dev-warning

Conversation

@jacekradko
Copy link
Copy Markdown
Member

@jacekradko jacekradko commented May 28, 2026

Follow-up to #8402, thanks to @jamesbvaughan for flagging this. The VITE_CLERK_UNSAFE_DISABLE_DEVELOPMENT_MODE_CONSOLE_WARNING shortcut only kicked in for SSR setups, because the env var is only read inside getPublicEnvVariables on the server and threaded through the rootAuthLoader payload. Client-only react-router has no loader, so clerkState is undefined and the flag was always undefined on the provider.

The fix is small: when __unsafeDisableDevelopmentModeConsoleWarning is absent from clerkState, fall back to getPublicEnvVariables(undefined). getEnvVariable already handles import.meta.env, so the same lookup works on the client. Explicit <ClerkProvider unsafe_disableDevelopmentModeConsoleWarning> props still win since they are spread last into restProps.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 28, 2026

🦋 Changeset detected

Latest commit: cd28ad1

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

This PR includes changesets to release 1 package
Name Type
@clerk/react-router 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

@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

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

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment May 28, 2026 2:09pm

Request Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 28, 2026

Open in StackBlitz

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@8682

@clerk/expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/hono

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/react

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

@clerk/react-router

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/ui

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

@clerk/upgrade

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

@clerk/vue

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

commit: cd28ad1

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro

Run ID: 19d910a0-1794-4665-adab-9ff6197bb98d

📥 Commits

Reviewing files that changed from the base of the PR and between bc91c54 and 4d3914a.

📒 Files selected for processing (2)
  • packages/react-router/src/client/ReactRouterClerkProvider.tsx
  • packages/react-router/src/client/__tests__/ClerkProvider.test.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/react-router/src/client/tests/ClerkProvider.test.tsx
  • packages/react-router/src/client/ReactRouterClerkProvider.tsx

📝 Walkthrough

Walkthrough

This PR adds support for reading the environment variable VITE_CLERK_UNSAFE_DISABLE_DEVELOPMENT_MODE_CONSOLE_WARNING directly on the client in React Router SPA mode. It imports getPublicEnvVariables, updates ReactRouterClerkProvider to fall back to the env var when Clerk internal state is unavailable, updates tests to mock SPA mode and ensure env stub cleanup, and adds a test asserting the env-var-driven flag is forwarded to InternalClerkProvider.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: enabling the VITE environment variable for dev-warning suppression in React Router SPA mode, which directly matches the PR's core objective.
Description check ✅ Passed The description is well-related to the changeset, providing context about the issue, the fix approach, and how property precedence is handled with explicit props.
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.

✏️ 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)
packages/react-router/src/client/__tests__/ClerkProvider.test.tsx (1)

19-24: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix SPA-mode coverage + make env cleanup reliable in ClerkProvider test

  • isSpaMode is mocked to always return false (packages/react-router/src/client/__tests__/ClerkProvider.test.tsx lines 19-24), so the test on lines 76-92 never exercises the SPA-only branch (assertPublishableKeyInSpaMode); the unsafe_disableDevelopmentModeConsoleWarning value is computed from env regardless of SPA mode.
  • vi.unstubAllEnvs() runs only at the end of the test body, so it can be skipped if an assertion fails; move it to afterEach (or use try/finally).
Suggested fix
+const isSpaModeMock = vi.fn(() => false);
+
 vi.mock('../../utils/assert', () => ({
   assertPublishableKeyInSpaMode: vi.fn(),
   assertValidClerkState: vi.fn(),
-  isSpaMode: () => false,
+  isSpaMode: isSpaModeMock,
   warnForSsr: vi.fn(),
 }));

 describe('ClerkProvider __internal_clerkUIUrl via clerkState', () => {
   beforeEach(() => {
     vi.clearAllMocks();
+    isSpaModeMock.mockReturnValue(false);
   });

   afterEach(() => {
     vi.clearAllMocks();
+    vi.unstubAllEnvs();
   });

   it('reads VITE_CLERK_UNSAFE_DISABLE_DEVELOPMENT_MODE_CONSOLE_WARNING in SPA mode where clerkState is absent', async () => {
+    isSpaModeMock.mockReturnValue(true);
     vi.stubEnv('VITE_CLERK_UNSAFE_DISABLE_DEVELOPMENT_MODE_CONSOLE_WARNING', 'true');
     const { ClerkProvider } = await import('../ReactRouterClerkProvider');

     render(
       <ClerkProvider publishableKey='pk_test_xxx'>
         <div>Test</div>
       </ClerkProvider>,
     );

     expect(mockClerkProvider).toHaveBeenCalledWith(
       expect.objectContaining({
         unsafe_disableDevelopmentModeConsoleWarning: true,
       }),
     );
-    vi.unstubAllEnvs();
   });
🤖 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/react-router/src/client/__tests__/ClerkProvider.test.tsx` around
lines 19 - 24, The test mocks isSpaMode to always return false, preventing the
SPA-only branch in assertPublishableKeyInSpaMode from being exercised and also
computes unsafe_disableDevelopmentModeConsoleWarning regardless of SPA mode;
update the mock so isSpaMode returns true for the SPA-specific test (or make it
configurable per test) to exercise assertPublishableKeyInSpaMode, and ensure env
cleanup uses vi.unstubAllEnvs() in an afterEach hook (or wrap the test body with
try/finally) so environment variables are reliably restored; locate usages of
isSpaMode, assertPublishableKeyInSpaMode,
unsafe_disableDevelopmentModeConsoleWarning and move vi.unstubAllEnvs() into
afterEach.
🤖 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.

Inline comments:
In `@packages/react-router/src/client/ReactRouterClerkProvider.tsx`:
- Around line 106-108: The boolean fallback for
unsafe_disableDevelopmentModeConsoleWarning currently uses || which treats an
explicit false as absent; change the expression in ReactRouterClerkProvider (the
unsafe_disableDevelopmentModeConsoleWarning assignment that references
__unsafeDisableDevelopmentModeConsoleWarning and
getPublicEnvVariables(...).unsafeDisableDevelopmentModeConsoleWarning) to use
the nullish coalescing operator (??) so that only null/undefined falls back to
the env value and an explicit false from the clerk state is preserved.

---

Outside diff comments:
In `@packages/react-router/src/client/__tests__/ClerkProvider.test.tsx`:
- Around line 19-24: The test mocks isSpaMode to always return false, preventing
the SPA-only branch in assertPublishableKeyInSpaMode from being exercised and
also computes unsafe_disableDevelopmentModeConsoleWarning regardless of SPA
mode; update the mock so isSpaMode returns true for the SPA-specific test (or
make it configurable per test) to exercise assertPublishableKeyInSpaMode, and
ensure env cleanup uses vi.unstubAllEnvs() in an afterEach hook (or wrap the
test body with try/finally) so environment variables are reliably restored;
locate usages of isSpaMode, assertPublishableKeyInSpaMode,
unsafe_disableDevelopmentModeConsoleWarning and move vi.unstubAllEnvs() into
afterEach.
🪄 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: f357fa39-c614-44ff-aa32-99c577af5c47

📥 Commits

Reviewing files that changed from the base of the PR and between b07afc4 and bc91c54.

📒 Files selected for processing (3)
  • .changeset/spa-dev-warning-env.md
  • packages/react-router/src/client/ReactRouterClerkProvider.tsx
  • packages/react-router/src/client/__tests__/ClerkProvider.test.tsx

Comment thread packages/react-router/src/client/ReactRouterClerkProvider.tsx
@jacekradko jacekradko merged commit b2820b1 into main May 28, 2026
43 checks passed
@jacekradko jacekradko deleted the jacek/react-router-spa-disable-dev-warning branch May 28, 2026 16:03
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