feat: add load
function to handle
hook to control css loading
#12677
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.
This PR introduces an additional
handle
hook function, similar to preload. The purpose of this function is to control which CSS assets should be loaded for a specific page or route.This functionality is necessary for dynamic component use case implemented using a combination of +page.server.js and +page.js. In the current version of SvelteKit, the CSS assets of all dynamically imported components are loaded on the page, regardless of whether or not they are actually used.
It is possible to remove unwanted css by redacting the html output using
transformPageChunk
but this feels more like a hack. It also does not work withinlineStyleThreshold
configuration property.The new function will allow SvelteKit users who use dynamic component imports to control which CSS assets should be loaded.
I'll address the items in the list below once I receive initial feedback on the solution. Thanks 🙏🏻
TODO:
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits
P.S.
Huge thank you to everyone involved in Svelte and SvelteKit projects ❤️