|
2 | 2 | * A combination of settings a fixed __PKG_VERSION__ during build time |
3 | 3 | * and the runtime __webpack_public_path__ config option (https://webpack.js.org/guides/public-path/). |
4 | 4 | * We explicitly set the public path in order to account for all chunk caching scenarios. |
5 | | - * A specific version of clerk.browser.js file should always try to load its corresponding chunk versions, |
| 5 | + * A specific version of ui.browser.js file should always try to load its corresponding chunk versions, |
6 | 6 | * otherwise we risk hitting caching issues. |
7 | 7 | * |
8 | 8 | * Scenario: |
9 | | - * 1. We release clerk-js@1.0.0 containing: clerk.browser.js, chunkA-1.0.0.js, chunkB-1.0.0.js |
| 9 | + * 1. We release @clerk/ui@1.0.0 containing: ui.browser.js, chunkA-1.0.0.js, chunkB-1.0.0.js |
10 | 10 | * 2. A user opens an app using Clerk |
11 | | - * 3. The browser downloads and caches `/npm/@clerk/clerk-js@latest/dist/clerk.browser.js` |
12 | | - * 4. chunkA is needed so the browser downloads and caches `/npm/@clerk/clerk-js@latest/dist/chunkA-1.0.0.js` |
13 | | - * 5. Meanwhile, we release clerk-js@1.2.0 containing: clerk.browser.js, chunkA-1.2.0.js, chunkB-1.2.0.js |
14 | | - * On our CDN, @clerk/clerk-js@latest now points to the new version |
| 11 | + * 3. The browser downloads and caches `/npm/@clerk/ui@latest/dist/ui.browser.js` |
| 12 | + * 4. chunkA is needed so the browser downloads and caches `/npm/@clerk/ui@latest/dist/chunkA-1.0.0.js` |
| 13 | + * 5. Meanwhile, we release ui@1.2.0 containing: ui.browser.js, chunkA-1.2.0.js, chunkB-1.2.0.js |
| 14 | + * On our CDN, @clerk/ui@latest now points to the new version |
15 | 15 | * 6. A user opens the app again |
16 | | - * 7. The browser loads `/npm/@clerk/clerk-js@latest/dist/clerk.browser.js` FROM CACHE (v1.0.0 file) |
17 | | - * 8. chunkA is needed so the browser loads `/npm/@clerk/clerk-js@latest/dist/chunkA-1.0.0.js` FROM CACHE (v1.0.0 file) |
18 | | - * 9. chunkB is needed for the first time. The cached v1.0.0 clerk.browser.js will try to load (request) |
19 | | - * `/npm/@clerk/clerk-js@latest/dist/chunkA-1.0.0.js` but because clerk-js@latest now resolves to v1.2.0, |
| 16 | + * 7. The browser loads `/npm/@clerk/ui@latest/dist/ui.browser.js` FROM CACHE (v1.0.0 file) |
| 17 | + * 8. chunkA is needed so the browser loads `/npm/@clerk/ui@latest/dist/chunkA-1.0.0.js` FROM CACHE (v1.0.0 file) |
| 18 | + * 9. chunkB is needed for the first time. The cached v1.0.0 ui.browser.js will try to load (request) |
| 19 | + * `/npm/@clerk/ui@latest/dist/chunkA-1.0.0.js` but because ui@latest now resolves to v1.2.0, |
20 | 20 | * the v1.0.0 file will not be found and the app will crash |
21 | 21 | * |
22 | 22 | * Solution: |
23 | | - * A given clerk.browser.js file will only load its corresponding chunks using a fixed version. Example: |
24 | | - * - clerk.browser.js loads from https://pk.accounts.dev/npm/@clerk/clerk-js@canary/dist/clerk.browser.js |
25 | | - * - all other chunks need to be loaded from https://pk.accounts.dev/npm/@clerk/clerk-js@__PKG_VERSION__/dist/ |
| 23 | + * A given ui.browser.js file will only load its corresponding chunks using a fixed version. Example: |
| 24 | + * - ui.browser.js loads from https://pk.accounts.dev/npm/@clerk/ui@canary/dist/ui.browser.js |
| 25 | + * - all other chunks need to be loaded from https://pk.accounts.dev/npm/@clerk/ui@__PKG_VERSION__/dist/ |
26 | 26 | */ |
27 | 27 | if (!__DEV__) { |
28 | | - const CLERKJS_NPM_PATH_REGEX = /(^.*\/@clerk\/clerk-js@)(.+?)(\/dist.*)/; |
| 28 | + const CLERK_UI_NPM_PATH_REGEX = /(^.*\/@clerk\/ui@)(.+?)(\/dist.*)/; |
29 | 29 | const setWebpackChunkPublicPath = () => { |
30 | 30 | try { |
31 | 31 | // @ts-expect-error |
32 | 32 | const scriptUrl = new URL(document.currentScript.src); |
33 | 33 | let hrefWithoutFilename = new URL(scriptUrl.href.split('/').slice(0, -1).join('/')).href; |
34 | 34 | hrefWithoutFilename += hrefWithoutFilename.endsWith('/') ? '' : '/'; |
35 | | - __webpack_public_path__ = hrefWithoutFilename.replace(CLERKJS_NPM_PATH_REGEX, `$1${__PKG_VERSION__}$3`); |
| 35 | + __webpack_public_path__ = hrefWithoutFilename.replace(CLERK_UI_NPM_PATH_REGEX, `$1${__PKG_VERSION__}$3`); |
36 | 36 | } catch { |
37 | 37 | // |
38 | 38 | } |
|
0 commit comments