Move version into payload to avoid rotating client chunks#16271
Open
Axeldeblen wants to merge 9 commits into
Open
Move version into payload to avoid rotating client chunks#16271Axeldeblen wants to merge 9 commits into
Axeldeblen wants to merge 9 commits into
Conversation
creating the test harness to validate client chunk rotation issue by testing chunk file names as well as chunk content
In the client we now read via the global version property rather than changing the name of the global object itself which was the source of bundle rotations
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/db64f31ae89c037d168a56e53845284c98ac888eOpen in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
|
| import { posixify } from '../utils/os.js'; | ||
|
|
||
| /** | ||
| <<<<<<< version-chunk-rotation-fix |
Contributor
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
closes
#12260
#9576
Somewhat adjacent to #14176
Context
For context we're running a svelte kit app and deploying many times per day. Currently svelte kit places the version into the client bundle, causing the chunks to rotate their hashes invalidating the caching whenever we deploy as described in #12260. This contributes to a degraded user experience in our case .e.g. a user will open a modal but the chunk will 404's the client chunks because the server version has rotated. We're using our git SHA as our version.
Description
This PR aims to solve the bundle rotating by refactoring the mechanism of how svelte kit defines and deliver the version within each client / server context.
Here is a simple visual flow of how the current
versionleaks into the client bundle via two seperate sources.[see](https://vite.dev/config/shared-options#define) for how
__SVELTEKIT_PAYLOAD__is replaced by viteBecause the client uses the version hash as part of the global definition we need to keep it stable if we want to avoid the cascade effect.
For that reason we are using a combination of config values to avoid any global collisions in embedded sveltekit version like in #14176
(Open to other suggestions on other combinations here)
Now the
version_hashis stable on globalThis between deploys we pass the actual version through the payload.Then we pass the version as a prop within the payload
N.B Perhaps
version_hashneeds to be renamed now as our definitions of "version" diverge a bit. I'd like to get a bit more feedback on the general approach here before continuing further refactoring.Tests
I've added some tests to demonstrate the current issue. In these tests we build multiple versions of the app with different version inputs and compare the content of the built chunks to avoid running into situations similar to #12779 (even though we are not using post build plugins).
Production testing
Our app is currently pinned to a slightly older version of kit but we're happy to test the core of these changes out on a subset of production traffic to help verify.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.I haven't made a change set yet but I will on confirmation the maintainers are happy with the direction of this PR.
Edits