-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: preserve shared client chunk hashes when the app version changes #16324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5c26123
fix: preserve shared client chunk hashes when the app version changes
dummdidumm e0e561f
still need the payload replacement for bundleStrategy !== 'split'
dummdidumm 6c1ce67
fix dev global constant replacements
teemingc 4a8db75
no, it has to be in the file with the global
teemingc 96ece24
Merge branch 'version-3' into stable-client-runtime
teemingc 3d950c3
add test
dummdidumm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@sveltejs/kit': patch | ||
| --- | ||
|
|
||
| fix: preserve shared client chunk hashes when the app version changes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| export const base = __SVELTEKIT_PAYLOAD__?.base ?? __SVELTEKIT_PATHS_BASE__; | ||
| export const assets = __SVELTEKIT_PAYLOAD__?.assets ?? base ?? __SVELTEKIT_PATHS_ASSETS__; | ||
| import { payload } from '../../../client/payload.js'; | ||
|
|
||
| export const base = payload.base ?? __SVELTEKIT_PATHS_BASE__; | ||
| export const assets = payload.assets ?? base ?? __SVELTEKIT_PATHS_ASSETS__; | ||
| export const app_dir = __SVELTEKIT_APP_DIR__; | ||
| export const hash_routing = __SVELTEKIT_HASH_ROUTING__; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // we expose this as a separate entry point (rather than treating client.js as the entry point) | ||
| // so that everything other than `start`/`load_css` can be treeshaken | ||
| export { start, load_css } from './client.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,24 @@ | ||
| // we expose this as a separate entry point (rather than treating client.js as the entry point) | ||
| // so that everything other than `start`/`load_css` can be treeshaken | ||
| export { start, load_css } from './client.js'; | ||
| /* in development or if `bundleStrategy` is 'split', this file is used as the entry point */ | ||
|
|
||
| import { set_payload } from './payload.js'; | ||
|
|
||
| /** @type {Promise<typeof import('./client-entry.js')>} */ | ||
| let client; | ||
|
|
||
| /** @param {import('types').SvelteKitPayload} payload */ | ||
| export function init(payload) { | ||
| set_payload(payload); | ||
| // Importing the client after setting the payload ensures that modules such as | ||
| // `$app/paths` can read it during initialization. | ||
| client ??= import('./client-entry.js'); | ||
| } | ||
|
|
||
| /** @param {Parameters<import('./client-entry.js').start>} args */ | ||
| export async function start(...args) { | ||
| return (await client).start(...args); | ||
| } | ||
|
|
||
| /** @param {Parameters<import('./client-entry.js').load_css>} args */ | ||
| export async function load_css(...args) { | ||
| return (await client).load_css(...args); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** @import {SvelteKitPayload} from 'types'; */ | ||
|
|
||
| /** | ||
| * Code inside the SvelteKit client runtime should only use this, not the global, | ||
| * so that the file hashes stay stable between rebuilds as long as the SvelteKit runtime doesn't change | ||
| */ | ||
| export let payload = __SVELTEKIT_PAYLOAD__ ?? /** @type {SvelteKitPayload} */ ({}); | ||
|
|
||
| /** @param {SvelteKitPayload} value */ | ||
| export function set_payload(value) { | ||
| payload = value; | ||
| } | ||
|
|
||
| // this makes Vite inject its dev client code as this module's first dependency | ||
| // so that global constant replacements are done before any other module evaluates. | ||
| // For build, it's inert. | ||
| import.meta.hot; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { execSync } from 'node:child_process'; | ||
| import path from 'node:path'; | ||
| import fs from 'node:fs'; | ||
| import { expect, test } from 'vitest'; | ||
|
|
||
| const timeout = 60_000; | ||
|
|
||
| test('SvelteKit runtime JS files stay stable between rebuilds', { timeout }, () => { | ||
| execSync('pnpm build', { | ||
| cwd: path.join(import.meta.dirname, '../'), | ||
| stdio: 'pipe', | ||
| timeout | ||
| }); | ||
|
|
||
| const before = get_client_chunk_name(); | ||
|
|
||
| execSync('pnpm build', { | ||
| cwd: path.join(import.meta.dirname, '../'), | ||
| stdio: 'pipe', | ||
| timeout | ||
| }); | ||
|
|
||
| expect(get_client_chunk_name()).toBe(before); | ||
|
|
||
| function get_client_chunk_name() { | ||
| const start_file = fs | ||
| .readdirSync( | ||
| path.join(import.meta.dirname, '../.svelte-kit/output/client/_app/immutable/entry') | ||
| ) | ||
| .find((file) => file.startsWith('start.')); | ||
| if (!start_file) { | ||
| throw new Error('start file not found, test needs adjustment'); | ||
| } | ||
| const start_content = fs.readFileSync( | ||
| path.join( | ||
| import.meta.dirname, | ||
| '../.svelte-kit/output/client/_app/immutable/entry', | ||
| start_file | ||
| ), | ||
| 'utf-8' | ||
| ); | ||
| const chunk_file = start_content.match(/import .+? from "\.\.\/chunks\/([^"]+)"/)?.[1]; | ||
| if (!chunk_file) { | ||
| throw new Error('chunk file not found, test needs adjustment'); | ||
| } | ||
| return chunk_file; | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.