fix: Stop re-loading already-loaded CSS during server-side route resolution #15014
+22
−13
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.
Changes:
load_css, grab the existing links'hrefattributes, which are absolute URLs to the CSS asset, and store them in a setI also switched the tests to use
page.locactor, which will poll until the default timeout to see if something has changed. This needs to happen prior to checking the array. We really should usepage.locatorrather thanpage.textContentin general.Observed behavior before this PR:
Basically, on server-side route resolution,
load_cssis re-loading CSS modules that are already in the document. You can see the behavior onpnpm -F test-basics build && pnpm -F test-basics previewby visitinghttp://localhost:4173/routing/form-get. Check the network requests for CSS, then type something into the input and click "submit". You'll see the CSS get loaded again.Tracing, the problem here is:
The initial load includes these links in the head:
On submission, the
__route.jsfile returns this line:load_csslooks like this:So it sees the following two deps:
However, the selector doesn't match, because the 0 href is relative.
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:.Edits