') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); fix(react): gate remote Clerk UI loader behind __BUILD_DISABLE_RHC__ by jacekradko · Pull Request #8773 · clerk/javascript · GitHub
Skip to content

fix(react): gate remote Clerk UI loader behind __BUILD_DISABLE_RHC__ - #8773

Merged
jacekradko merged 2 commits into
mainfrom
jacek/chrome-ext-ui-rhc-gate
Jun 9, 2026
Merged

fix(react): gate remote Clerk UI loader behind __BUILD_DISABLE_RHC__#8773
jacekradko merged 2 commits into
mainfrom
jacek/chrome-ext-ui-rhc-gate

Conversation

@jacekradko

@jacekradkojacekradko commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

@clerk/chrome-extension was getting rejected from the Chrome Web Store under MV3 because the bundle ships a remote script loader for @clerk/ui's ui.browser.js. The extension already bundles the UI via @clerk/ui/no-rhc so the loader never runs, but getClerkUIEntryChunk wasn't gating it behind __BUILD_DISABLE_RHC__ the way getClerkJsEntryChunk already does for clerk-js. Gating it lets the loader (and the createElement('script') it uses) tree-shake out of the extension build.

The search-for-rhc.mjs postbuild check should have caught this since it already greps for /npm/@clerk/ui, but its directory mode was missing -r, so grep never looked inside dist and always came back clean. That's fixed here too, which is why it goes in the same PR as the gate rather than on its own. I rebuilt react and the extension to confirm the RHC strings are gone and the check passes, then pointed the fixed checker at a planted URL to make sure it still fails when there's something to find.

Closes#8770

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Chrome extension builds now exclude remote UI script loaders.
    • No-remote-code React builds now properly handle remote UI script loading.
  • Chores

    • Improved recursive search in build configuration utilities.

getClerkUIEntryChunk did not gate loadClerkUIScript behind
__BUILD_DISABLE_RHC__, so no-remote-code builds (e.g. @clerk/chrome-extension)
shipped the @clerk/ui ui.browser.js CDN loader as unreachable code. The Chrome
Web Store rejects this under Manifest V3 even though it never runs. Gate it like
getClerkJsEntryChunk so it dead-code-eliminates out of the bundle.
Also fix scripts/search-for-rhc.mjs directory mode, which was missing -r and so
never descended into dist, silently passing. This made the chrome-extension
postbuild and ui check:no-rhc guards no-ops.
Closes#8770
@changeset-bot

changeset-botBot commented Jun 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fb6ad51

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

This PR includes changesets to release 6 packages
NameType
@clerk/chrome-extensionPatch
@clerk/reactPatch
@clerk/expoPatch
@clerk/nextjsPatch
@clerk/react-routerPatch
@clerk/tanstack-react-startPatch

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

vercelBot commented Jun 8, 2026

Copy link
Copy Markdown

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

ProjectDeploymentActionsUpdated (UTC)
clerk-js-sandboxReadyReadyPreview, CommentJun 9, 2026 3:20am

Request Review

@coderabbitai

coderabbitaiBot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro

Run ID: cca227c4-2999-4f5f-89bc-dc4dce38e9be

📥 Commits

Reviewing files that changed from the base of the PR and between c8ff729 and fb6ad51.

📒 Files selected for processing (1)
  • packages/react/src/isomorphicClerk.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react/src/isomorphicClerk.ts

📝 Walkthrough

Walkthrough

This PR gates the Clerk UI remote script loader behind the __BUILD_DISABLE_RHC__ build flag in the React package, documents the resulting Chrome extension cleanup, and updates the RHC search utility to traverse directories recursively.

Changes

Remote Code Gate for Clerk UI

Layer / File(s)Summary
Build-time gate for Clerk UI remote loader
packages/react/src/isomorphicClerk.ts, .changeset/react-gate-ui-loader-norhc.md
getClerkUIEntryChunk is wrapped with a !__BUILD_DISABLE_RHC__ guard so it returns undefined when the flag is enabled, preventing the remote UI CDN loader from being bundled; unchanged behavior when the flag is not set.
Chrome extension cleanup documentation and RHC search improvement
.changeset/chrome-extension-strip-ui-rhc-loader.md, scripts/search-for-rhc.mjs
Adds a changeset documenting removal of the remote @clerk/ui loader from the Chrome extension bundle and updates asyncSearchRHC to use grep -r for directory searches so nested files are checked.

🎯 2 (Simple) | ⏱️ ~10 minutes


A gate to block the script so tight,
No remote code will bundle in flight!
Chrome's manifest won't fuss and fight,
Extensions pass inspection just right. 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title clearly and concisely describes the main change: gating the remote Clerk UI loader behind a build-time flag to enable tree-shaking in builds that disable remote-hosted code.
Linked Issues check✅ PassedThe PR fully addresses issue #8770 by implementing a build-time gate for the remote UI script loader, enabling tree-shaking for no-RHC builds and fixing the postbuild verification script.
Out of Scope Changes check✅ PassedAll changes are directly related to the stated objective: gating the remote UI loader and fixing the recursive directory search in the verification script.
Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@pkg-pr-new

pkg-pr-newBot commented Jun 8, 2026

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/hono

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/react

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

@clerk/react-router

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/ui

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

@clerk/upgrade

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

@clerk/vue

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

commit: fb6ad51

@github-actions

Copy link
Copy Markdown
Contributor

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

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

@jacekradko
jacekradko requested a review from tmilewskiJune 9, 2026 03:19
@github-actions

Copy link
Copy Markdown
Contributor

API Changes Report

Generated by Break Check on 2026-06-09T03:25:44.791Z

Summary

MetricCount
Packages analyzed19
Packages with changes0
🔴 Breaking changes0
🟡 Non-breaking changes0
🟢 Additions0

Note
Break Check could not snapshot 3 subpaths; the diff below excludes them.

  • @clerk/astro ./env: Internal Error: Unable to determine module for: /home/runner/_work/javascript/javascript/packages/astro/env.d.ts You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.
  • @clerk/shared ./cookie: Internal Error: Unable to follow symbol for "Cookies" You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.
  • @clerk/testing ./cypress: Symbol not found for identifier: Cypress

No API Changes Detected

All packages have stable APIs with no detected changes.


Report generated by Break Check

Last ran on fb6ad51.

@jacekradko
jacekradko merged commit 0c854c3 into mainJun 9, 2026
48 checks passed
@jacekradko
jacekradko deleted the jacek/chrome-ext-ui-rhc-gate branch June 9, 2026 16:12
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@clerk/chrome-extension bundles remote UI script loader, rejected by Chrome Web Store under Manifest V3

3 participants

@jacekradko@tmilewski@wobsoriano