feat: add injectCss option to opt out of global CSS - #307
Open
Hossein-Mirazimi wants to merge 2 commits into
Open
feat: add injectCss option to opt out of global CSS#307Hossein-Mirazimi wants to merge 2 commits into
Hossein-Mirazimi wants to merge 2 commits into
Conversation
✅ Deploy Preview for nuxt-leaflet ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
🔗 Linked issue
resolves #306
❓ Type of change
📚 Description
The module pushes
leaflet/dist/leaflet.cssintonuxt.options.cssunconditionally, soLeaflet's stylesheet ends up in the global entry CSS and is render-blocking on every
route. In an app where maps live on one or two pages, all the other pages still download
and parse it before they can paint, with no way to opt out.
This adds an
injectCssmodule option, defaulting totrue, so the current behaviour isunchanged for existing users:
With
injectCss: false, the module ships no stylesheet and you import it yourself in thecomponents that render a map, letting Vite bundle it only into the chunks that need it:
The option also gates the two
leaflet.markerclusterstylesheets, soinjectCss: falseconsistently means "the module injects no global CSS" — otherwise the option would have no
effect for markercluster users. The guide documents the manual imports for that case.
Documentation: adds a "Performance" page to the Guide section
(
docs/guide/performance.md, linked in the VitePress sidebar) explaining why the globalinjection is render-blocking, how to opt out, the caveat that you then own the imports, and
the plugin stylesheets.
Tests: adds a no-inject-css fixture (
injectCss: false, with the app importing thestylesheet itself) and test/no-inject-css.test.ts, which renders the page and asserts
leaflet/dist/leaflet.css is absent from nuxt.options.css.