Skip to content

Commit 0c854c3

Browse files
authored
fix(react): gate remote Clerk UI loader behind __BUILD_DISABLE_RHC__ (#8773)
1 parent 7ae5a61 commit 0c854c3

4 files changed

Lines changed: 27 additions & 11 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/chrome-extension': patch
3+
---
4+
5+
Strip the remotely-hosted `@clerk/ui` script loader from the bundle. The extension SDK already ships Clerk UI bundled via `@clerk/ui/no-rhc`, but the CDN loader for `ui.browser.js` (a dynamically injected `<script>` tag) remained in the build as unreachable code. The Chrome Web Store rejects this under Manifest V3's prohibition on remotely hosted code even though it never runs. It is now removed at build time.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/react': patch
3+
---
4+
5+
Gate the remote Clerk UI script loader behind `__BUILD_DISABLE_RHC__` so no-remote-code builds (such as `@clerk/chrome-extension`) dead-code-eliminate the `ui.browser.js` CDN loader, matching the existing behavior for the clerk-js loader. Standard browser apps are unaffected and continue to hotload Clerk UI from the CDN.

packages/react/src/isomorphicClerk.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -576,19 +576,25 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
576576
return undefined;
577577
}
578578

579-
await loadClerkUIScript({
580-
...this.options,
581-
publishableKey: this.#publishableKey,
582-
proxyUrl: this.proxyUrl,
583-
domain: this.domain,
584-
nonce: this.options.nonce,
585-
});
579+
// Skip the remote UI loader in no-RHC builds (e.g. Chrome extensions) so the CDN script
580+
// injector is dead-code-eliminated from the bundle, mirroring getClerkJsEntryChunk.
581+
if (!__BUILD_DISABLE_RHC__) {
582+
await loadClerkUIScript({
583+
...this.options,
584+
publishableKey: this.#publishableKey,
585+
proxyUrl: this.proxyUrl,
586+
domain: this.domain,
587+
nonce: this.options.nonce,
588+
});
589+
590+
if (!global.__internal_ClerkUICtor) {
591+
throw new Error('Failed to download latest Clerk UI. Contact support@clerk.com.');
592+
}
586593

587-
if (!global.__internal_ClerkUICtor) {
588-
throw new Error('Failed to download latest Clerk UI. Contact support@clerk.com.');
594+
return global.__internal_ClerkUICtor;
589595
}
590596

591-
return global.__internal_ClerkUICtor;
597+
return undefined;
592598
}
593599

594600
public on: Clerk['on'] = (...args) => {

scripts/search-for-rhc.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async function asyncSearchRHC(name, search, regex = false) {
1414
const flag = regex ? 'E' : 'F';
1515
const cmd = () =>
1616
targetType === 'directory'
17-
? $`grep -${flag}q --include=\\*.js --include=\\*.mjs ${search} ${target}`
17+
? $`grep -r${flag}q --include=\\*.js --include=\\*.mjs ${search} ${target}`
1818
: $`grep -${flag}q ${search} ${target}`;
1919

2020
if ((await cmd().exitCode) === 0) {

0 commit comments

Comments
 (0)