Skip to content

Commit f7472e2

Browse files
fix(elements): Fix elements router usage (#4513)
Co-authored-by: Bryce Kalow <bryce@clerk.dev>
1 parent f5f6c4d commit f7472e2

File tree

18 files changed

+119
-133
lines changed

18 files changed

+119
-133
lines changed

.changeset/empty-dots-confess.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@clerk/elements': patch
3+
'@clerk/nextjs': patch
4+
'@clerk/shared': patch
5+
'@clerk/types': patch
6+
'@clerk/clerk-js': patch
7+
---
8+
9+
Fixes issues in `ClerkRouter` that were causing inaccurate pathnames within Elements flows. Also fixes a dependency issue where `@clerk/elements` was pulling in the wrong version of `@clerk/shared`.

package-lock.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/clerk-js/bundlewatch.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{ "path": "./dist/clerk.js", "maxSize": "707kB" },
44
{ "path": "./dist/clerk.browser.js", "maxSize": "75kB" },
55
{ "path": "./dist/clerk.headless.js", "maxSize": "48kB" },
6-
{ "path": "./dist/ui-common*.js", "maxSize": "87KB" },
6+
{ "path": "./dist/ui-common*.js", "maxSize": "88KB" },
77
{ "path": "./dist/vendors*.js", "maxSize": "70KB" },
88
{ "path": "./dist/coinbase*.js", "maxSize": "58KB" },
99
{ "path": "./dist/createorganization*.js", "maxSize": "5KB" },

packages/clerk-js/jest.setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ if (typeof window !== 'undefined') {
3535

3636
global.__PKG_NAME__ = '';
3737
global.__PKG_VERSION__ = '';
38+
global.BUILD_ENABLE_NEW_COMPONENTS = '';
3839

3940
//@ts-expect-error
4041
global.IntersectionObserver = class IntersectionObserver {

packages/clerk-js/rspack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const common = ({ mode }) => {
4242
__DEV__: isDevelopment(mode),
4343
__PKG_VERSION__: JSON.stringify(packageJSON.version),
4444
__PKG_NAME__: JSON.stringify(packageJSON.name),
45+
BUILD_ENABLE_NEW_COMPONENTS: JSON.stringify(process.env.BUILD_ENABLE_NEW_COMPONENTS),
4546
}),
4647
new rspack.EnvironmentPlugin({
4748
CLERK_ENV: mode,

packages/clerk-js/src/core/clerk.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,14 @@ export class Clerk implements ClerkInterface {
340340
this.#loaded = await this.#loadInNonStandardBrowser();
341341
}
342342

343-
if (clerkIsLoaded(this)) {
344-
this.__experimental_ui = new UI({
345-
router: this.#options.__experimental_router,
346-
clerk: this,
347-
options: this.#options,
348-
});
343+
if (BUILD_ENABLE_NEW_COMPONENTS) {
344+
if (clerkIsLoaded(this)) {
345+
this.__experimental_ui = new UI({
346+
router: this.#options.__experimental_router,
347+
clerk: this,
348+
options: this.#options,
349+
});
350+
}
349351
}
350352
};
351353

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ declare module '@clerk/ui/styles.css' {
22
const content: string;
33
export default content;
44
}
5+
6+
declare const BUILD_ENABLE_NEW_COMPONENTS: string;

packages/clerk-js/src/ui/new/index.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,23 @@ export class UI {
3333
this.clerk = clerk;
3434
this.options = options;
3535

36-
// register components
37-
this.register('SignIn', {
38-
type: 'component',
39-
load: () =>
40-
import(/* webpackChunkName: "rebuild--sign-in" */ '@clerk/ui/sign-in').then(({ SignIn }) => ({
41-
default: SignIn,
42-
})),
43-
});
44-
this.register('SignUp', {
45-
type: 'component',
46-
load: () =>
47-
import(/* webpackChunkName: "rebuild--sign-up" */ '@clerk/ui/sign-up').then(({ SignUp }) => ({
48-
default: SignUp,
49-
})),
50-
});
36+
if (BUILD_ENABLE_NEW_COMPONENTS) {
37+
// register components
38+
this.register('SignIn', {
39+
type: 'component',
40+
load: () =>
41+
import(/* webpackChunkName: "rebuild--sign-in" */ '@clerk/ui/sign-in').then(({ SignIn }) => ({
42+
default: SignIn,
43+
})),
44+
});
45+
this.register('SignUp', {
46+
type: 'component',
47+
load: () =>
48+
import(/* webpackChunkName: "rebuild--sign-up" */ '@clerk/ui/sign-up').then(({ SignUp }) => ({
49+
default: SignUp,
50+
})),
51+
});
52+
}
5153
}
5254

5355
// Mount a component from the registry

packages/clerk-js/turbo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"extends": ["//"],
33
"tasks": {
44
"build": {
5+
"env": ["BUILD_ENABLE_NEW_COMPONENTS"],
56
"inputs": [
67
"*.d.ts",
78
"bundlewatch.config.json",

packages/elements/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"test:cache:clear": "jest --clearCache --useStderr"
7272
},
7373
"dependencies": {
74-
"@clerk/shared": "2.11.5",
7574
"@clerk/types": "^4.30.0",
7675
"@radix-ui/react-form": "^0.1.0",
7776
"@radix-ui/react-slot": "^1.1.0",
@@ -82,6 +81,7 @@
8281
"devDependencies": {
8382
"@clerk/clerk-react": "5.15.1",
8483
"@clerk/eslint-config-custom": "*",
84+
"@clerk/shared": "2.11.5",
8585
"@statelyai/inspect": "^0.4.0",
8686
"@types/node": "^18.19.33",
8787
"@types/react": "*",
@@ -94,6 +94,8 @@
9494
"typescript": "*"
9595
},
9696
"peerDependencies": {
97+
"@clerk/shared": "2.x",
98+
"next": "^13.5.4 || ^14.0.3 || ^15",
9799
"react": "^18.0.0 || ^19.0.0-beta",
98100
"react-dom": "^18.0.0 || ^19.0.0-beta"
99101
},

0 commit comments

Comments
 (0)