Skip to content

Commit bddd5f9

Browse files
authored
fix(clerk-js): Update sandbox with separate UI module (#7398)
1 parent 2b82a6e commit bddd5f9

File tree

9 files changed

+28
-1
lines changed

9 files changed

+28
-1
lines changed

.changeset/blue-stars-tie.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"clean": "turbo clean",
1313
"dev": "TURBO_UI=0 FORCE_COLOR=1 turbo dev --filter=@clerk/* --filter=!@clerk/expo --filter=!@clerk/tanstack-react-start --filter=!@clerk/chrome-extension",
1414
"dev:js": "TURBO_UI=0 FORCE_COLOR=1 turbo dev:current --filter=@clerk/clerk-js",
15+
"dev:sandbox": "TURBO_UI=0 FORCE_COLOR=1 turbo dev:sandbox --filter=@clerk/clerk-js --filter=@clerk/ui",
1516
"format": "turbo format && node scripts/format-non-workspace.mjs",
1617
"format:check": "turbo format:check && node scripts/format-non-workspace.mjs --check",
1718
"preinstall": "npx only-allow pnpm",

packages/clerk-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"build:analyze": "rspack build --config rspack.config.js --env production --env variant=\"clerk.browser\" --env analysis --analyze",
3636
"build:bundle": "pnpm clean && rspack build --config rspack.config.js --env production",
3737
"build:declarations": "tsc -p tsconfig.declarations.json",
38-
"build:sandbox": "rspack build --config rspack.config.js --env production --env sandbox",
38+
"build:sandbox": "pnpm --filter @clerk/ui build:umd && rspack build --config rspack.config.js --env production --env sandbox",
3939
"build:stats": "rspack build --config rspack.config.js --env production --json=stats.json --env variant=\"clerk.browser\"",
4040
"bundlewatch": "FORCE_COLOR=1 bundlewatch --config bundlewatch.config.json",
4141
"bundlewatch:fix": "node bundlewatch-fix.mjs",

packages/clerk-js/rspack.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,17 @@ const prodConfig = ({ mode, env, analysis }) => {
252252
? {
253253
entry: { sandbox: './sandbox/app.ts' },
254254
plugins: [
255+
new rspack.CopyRspackPlugin({
256+
patterns: [{ from: path.resolve(__dirname, '../ui/dist/*.js'), to: '[name][ext]' }],
257+
}),
255258
new rspack.HtmlRspackPlugin({
256259
minify: false,
257260
template: './sandbox/template.html',
258261
inject: false,
259262
hash: true,
263+
templateParameters: {
264+
uiScriptUrl: './ui.browser.js',
265+
},
260266
}),
261267
],
262268
}
@@ -456,6 +462,9 @@ const devConfig = ({ mode, env }) => {
456462
minify: false,
457463
template: './sandbox/template.html',
458464
inject: false,
465+
templateParameters: {
466+
uiScriptUrl: 'http://localhost:4001/npm/ui.browser.js',
467+
},
459468
}),
460469
].filter(Boolean),
461470
devtool: 'eval-cheap-source-map',

packages/clerk-js/sandbox/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ void (async () => {
378378
...(componentControls.clerk.getProps() ?? {}),
379379
signInUrl: '/sign-in',
380380
signUpUrl: '/sign-up',
381+
clerkUiCtor: window.__internal_ClerkUiCtor,
381382
});
382383
renderCurrentRoute();
383384
updateVariables();

packages/clerk-js/sandbox/template.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@
355355
</main>
356356

357357
<!-- This app is in the Team SDK organization. -->
358+
<!-- Load the UI bundle first, so window.__internal_ClerkUiCtor is available -->
359+
<script
360+
type="text/javascript"
361+
src="<%= uiScriptUrl %>"
362+
crossorigin="anonymous"
363+
></script>
358364
<script
359365
type="text/javascript"
360366
src="/<%= htmlRspackPlugin.files.js[0] %>"

packages/clerk-js/src/global.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ const __BUILD_VARIANT_CHIPS__: boolean;
1717
interface Window {
1818
__internal_onBeforeSetActive: (intent?: 'sign-out') => Promise<void> | void;
1919
__internal_onAfterSetActive: () => Promise<void> | void;
20+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
21+
__internal_ClerkUiCtor?: import('@clerk/shared/types').ClerkUiConstructor;
2022
}

packages/ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"clean": "rimraf ./dist",
5555
"dev": "tsdown --watch src",
5656
"dev:origin": "rspack serve --config rspack.config.js --env devOrigin=http://localhost:${PORT:-4001}",
57+
"dev:sandbox": "rspack serve --config rspack.config.js --env devOrigin=http://localhost:4001",
5758
"format": "node ../../scripts/format-package.mjs",
5859
"format:check": "node ../../scripts/format-package.mjs --check",
5960
"lint:attw": "attw --pack . --exclude-entrypoints themes/shadcn.css --profile esm-only",

turbo.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@
7979
"dependsOn": ["^build", "dev"],
8080
"persistent": true
8181
},
82+
"dev:sandbox": {
83+
"cache": false,
84+
"dependsOn": ["^build"],
85+
"persistent": true
86+
},
8287
"clean": {
8388
"cache": false
8489
},

0 commit comments

Comments
 (0)