Skip to content

fix(react): conditionally load UI scripts to prevent document.createE…#7769

Open
chriscanin wants to merge 2 commits intomainfrom
chris/document-create-element-bug
Open

fix(react): conditionally load UI scripts to prevent document.createE…#7769
chriscanin wants to merge 2 commits intomainfrom
chris/document-create-element-bug

Conversation

@chriscanin
Copy link
Member

@chriscanin chriscanin commented Feb 4, 2026

Description

This fixes a bug that is happening with core-3 expo release:

Call Stack
  loadClerkUIScript (node_modules/@clerk/expo/node_modules/@clerk/shared/dist/runtime/loadClerkJsScript.js:114:25)
  next (<native>)
  asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17)
  _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:27)
  Promise$argument_0 (node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:12)
  tryCallTwo (address at (InternalBytecode.js:1:1222)
  doResolve (address at (InternalBytecode.js:1:2541)
  Promise (address at (InternalBytecode.js:1:1318)
  <anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:23)
  apply (<native>)
  <global> (node_modules/@clerk/expo/node_modules/@clerk/shared/dist/runtime/loadClerkJsScript.js:102:24)
  _IsomorphicClerk#getClerkUiEntryChunk (node_modules/@clerk/expo/node_modules/@clerk/react/dist/index.js:3440:57)
  next (<native>)
  asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17)
  _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:27)
  Promise$argument_0 (node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:12)
  tryCallTwo (address at (InternalBytecode.js:1:1222)
  doResolve (address at (InternalBytecode.js:1:2541)
  Promise (address at (InternalBytecode.js:1:1318)
  <anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:23)
  apply (<native>)
  _IsomorphicClerk#getClerkUiEntryChunk (node_modules/@clerk/expo/node_modules/@clerk/react/dist/index.js:3433:29)
  _IsomorphicClerk#getEntryChunks (node_modules/@clerk/expo/node_modules/@clerk/react/dist/index.js:3399:58)
  next (<native>)
  asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17)
  _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:27)
  Promise$argument_0 (node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:12)
  tryCallTwo (address at (InternalBytecode.js:1:1222)
  doResolve (address at (InternalBytecode.js:1:2541)
  Promise (address at (InternalBytecode.js:1:1318)
  <anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:23)
  apply (<native>)
  _IsomorphicClerk#getEntryChunks (node_modules/@clerk/expo/node_modules/@clerk/react/dist/index.js:3389:23)
  _IsomorphicClerk#constructor (node_modules/@clerk/expo/node_modules/@clerk/react/dist/index.js:3300:31)
  _IsomorphicClerk.getOrCreateInstance (node_modules/@clerk/expo/node_modules/@clerk/react/dist/index.js:3326:57)
  useLoadedIsomorphicClerk (node_modules/@clerk/expo/node_modules/@clerk/react/dist/index.js:3583:95)
  ClerkProviderBase (node_modules/@clerk/expo/node_modules/@clerk/react/dist/index.js:3561:68)
  callComponent.reactStackBottomFrame (node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js:15887:29)
  renderWithHooks (node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js:3857:40)
  updateFunctionComponent (node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js:7289:34)
  beginWork (node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js:8541:41)
  runWithFiberInDEV (node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js:683:21)
  performUnitOfWork (node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js:12220:39)
  workLoopSync (node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js:12044:58)
  renderRootSync (node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js:12024:23)
  performWorkOnRoot (node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js:11551:27)
  performSyncWorkOnRoot (node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js:3088:24)
  flushSyncWorkAcrossRoots_impl (node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js:2942:42)
  processRootScheduleInMicrotask (node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js:2973:36)
  scheduleMicrotask$argument_0 (node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js:3108:47) 

Call Stack
  construct (<native>)
  apply (<native>)
  _construct (node_modules/@babel/runtime/helpers/construct.js:4:65)
  Wrapper (node_modules/@babel/runtime/helpers/wrapNativeSuper.js:15:23)
  construct (<native>)
  _callSuper (node_modules/@babel/runtime/helpers/callSuper.js:5:108)
  NamelessError (node_modules/@expo/metro-runtime/src/metroServerLogs.native.ts:102:20)
  captureCurrentStack (node_modules/@expo/metro-runtime/src/metroServerLogs.native.ts:106:27)
  HMRClient.log (node_modules/@expo/metro-runtime/src/metroServerLogs.native.ts:39:79)
  console.level (node_modules/react-native/Libraries/Core/setUpDeveloperTools.js:41:24)
  _IsomorphicClerk#getEntryChunks (node_modules/@clerk/expo/node_modules/@clerk/react/dist/index.js:3411:20)
  throw (<native>)
  asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17)
  _throw (node_modules/@babel/runtime/helpers/asyncToGenerator.js:20:27)
  tryCallOne (address at (InternalBytecode.js:1:1180)
  anonymous (address at (InternalBytecode.js:1:1874)

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:

Summary by CodeRabbit

Bug Fixes

  • Fixed a ReferenceError that occurred when the application was executed in non-browser environments, including Node.js and server-side rendering contexts. UI scripts are now conditionally loaded only when running in standard browser environments, improving overall reliability and compatibility across various deployment scenarios, server configurations, and specialized execution contexts.

@changeset-bot
Copy link

changeset-bot bot commented Feb 4, 2026

🦋 Changeset detected

Latest commit: d92209a

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

This PR includes changesets to release 6 packages
Name Type
@clerk/react Patch
@clerk/chrome-extension Patch
@clerk/expo Patch
@clerk/nextjs Patch
@clerk/react-router Patch
@clerk/tanstack-react-start 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

vercel bot commented Feb 4, 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 Feb 4, 2026 11:38pm

Request Review

@chriscanin
Copy link
Member Author

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @chriscanin - the snapshot version command generated the following package versions:

Package Version
@clerk/agent-toolkit 0.3.0-snapshot.v20260204233758
@clerk/astro 3.0.0-snapshot.v20260204233758
@clerk/backend 3.0.0-snapshot.v20260204233758
@clerk/chrome-extension 3.0.0-snapshot.v20260204233758
@clerk/clerk-js 6.0.0-snapshot.v20260204233758
@clerk/dev-cli 1.0.0-snapshot.v20260204233758
@clerk/expo 3.0.0-snapshot.v20260204233758
@clerk/expo-passkeys 1.0.0-snapshot.v20260204233758
@clerk/express 2.0.0-snapshot.v20260204233758
@clerk/fastify 2.7.0-snapshot.v20260204233758
@clerk/localizations 4.0.0-snapshot.v20260204233758
@clerk/msw 0.0.1-snapshot.v20260204233758
@clerk/nextjs 7.0.0-snapshot.v20260204233758
@clerk/nuxt 2.0.0-snapshot.v20260204233758
@clerk/react 6.0.0-snapshot.v20260204233758
@clerk/react-router 3.0.0-snapshot.v20260204233758
@clerk/shared 4.0.0-snapshot.v20260204233758
@clerk/tanstack-react-start 1.0.0-snapshot.v20260204233758
@clerk/testing 2.0.0-snapshot.v20260204233758
@clerk/ui 1.0.0-snapshot.v20260204233758
@clerk/upgrade 2.0.0-snapshot.v20260204233758
@clerk/vue 2.0.0-snapshot.v20260204233758

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/agent-toolkit

npm i @clerk/agent-toolkit@0.3.0-snapshot.v20260204233758 --save-exact

@clerk/astro

npm i @clerk/astro@3.0.0-snapshot.v20260204233758 --save-exact

@clerk/backend

npm i @clerk/backend@3.0.0-snapshot.v20260204233758 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@3.0.0-snapshot.v20260204233758 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@6.0.0-snapshot.v20260204233758 --save-exact

@clerk/dev-cli

npm i @clerk/dev-cli@1.0.0-snapshot.v20260204233758 --save-exact

@clerk/expo

npm i @clerk/expo@3.0.0-snapshot.v20260204233758 --save-exact

@clerk/expo-passkeys

npm i @clerk/expo-passkeys@1.0.0-snapshot.v20260204233758 --save-exact

@clerk/express

npm i @clerk/express@2.0.0-snapshot.v20260204233758 --save-exact

@clerk/fastify

npm i @clerk/fastify@2.7.0-snapshot.v20260204233758 --save-exact

@clerk/localizations

npm i @clerk/localizations@4.0.0-snapshot.v20260204233758 --save-exact

@clerk/msw

npm i @clerk/msw@0.0.1-snapshot.v20260204233758 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@7.0.0-snapshot.v20260204233758 --save-exact

@clerk/nuxt

npm i @clerk/nuxt@2.0.0-snapshot.v20260204233758 --save-exact

@clerk/react

npm i @clerk/react@6.0.0-snapshot.v20260204233758 --save-exact

@clerk/react-router

npm i @clerk/react-router@3.0.0-snapshot.v20260204233758 --save-exact

@clerk/shared

npm i @clerk/shared@4.0.0-snapshot.v20260204233758 --save-exact

@clerk/tanstack-react-start

npm i @clerk/tanstack-react-start@1.0.0-snapshot.v20260204233758 --save-exact

@clerk/testing

npm i @clerk/testing@2.0.0-snapshot.v20260204233758 --save-exact

@clerk/ui

npm i @clerk/ui@1.0.0-snapshot.v20260204233758 --save-exact

@clerk/upgrade

npm i @clerk/upgrade@2.0.0-snapshot.v20260204233758 --save-exact

@clerk/vue

npm i @clerk/vue@2.0.0-snapshot.v20260204233758 --save-exact

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

This pull request introduces a conditional loading mechanism for Clerk UI scripts to prevent ReferenceError exceptions. A new changeset documents this patch-level fix. In isomorphicClerk.ts, the code now conditionally loads the UI constructor based on a shouldLoadUi flag, which is determined by whether Clerk is explicitly provided and whether standardBrowser context is available. The early fetch of the UI constructor has been removed in favor of lazy loading, with the appropriate value passed to the clerk.load method. No public APIs or exported signatures were modified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The linked issue CORE-3 provides no specific coding requirements or objectives to validate; it only contains a vague description offering no actionable guidance for assessing code changes. Review the linked issue to ensure it contains specific coding requirements or objectives that the PR implementation should address.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: conditionally loading UI scripts to fix a document.createElement issue, which aligns with the PR's primary objective to prevent ReferenceError crashes in React Native environments.
Out of Scope Changes check ✅ Passed All changes are directly related to the PR's stated objective of conditionally loading UI scripts to fix the document.createElement crash in React Native environments.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 4, 2026

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@7769

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/react

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

@clerk/react-router

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/ui

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

@clerk/upgrade

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

@clerk/vue

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

commit: d92209a

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