close
Skip to content

fix: modulePreload false#13973

Merged
patak-cat merged 2 commits into
mainfrom
fix/module-preload-false
Jul 31, 2023
Merged

fix: modulePreload false#13973
patak-cat merged 2 commits into
mainfrom
fix/module-preload-false

Conversation

@patak-cat

Copy link
Copy Markdown
Member

Fixes #10773

Description

We currently share the same preload helper for injecting CSS stylesheets of dynamic imports. Even when modulePreload is set to false, we still need the preload import helper and preserve the CSS styles for the dynamically imported module.

We already had a test case for modulePreload: false, but one of the checks was wrong.

This fix isn't ideal, users that set modulePreload false would probably expect the import helper to be avoided. But at least the behavior is correct after this PR.

Related issue:

#13952 one isn't easy to solve as we need import.meta.url in the transform hook, and populate the deps for the dynamic import in generateBundle. If we don't find a good way to find if the preload helper is needed at transform time, maybe we could at least reduce the helper that is quite verbose now with no deps and then replace it back in generateBundle (even if we leave some white space to avoid messing with sourcemaps).


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@patak-cat patak-cat added feat: css p3-minor-bug An edge case that only affects very specific usage (priority) feat: build labels Jul 28, 2023

@bluwy bluwy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can merge this as a stop gap for now. I also think it's not ideal, but I'm not really sure how to fix it. Maybe we can improve preloading overall later to tackle #13952, slim it down, different preloads for JS or CSS only, that PR to reduce preload deps string size etc at once.

Comment thread packages/vite/src/node/plugins/importAnalysisBuild.ts
@patak-cat

Copy link
Copy Markdown
Member Author

Agreed. Not directly related, but the way we handle preloads may also get in the way to stabilize renderBuiltUrl. See #13834 (comment). I also don't know how to properly fix that one though if we need to wait until generateBundle. We could try add something to augmentChunkHash, using dynamicImports to precalculate all the URLs we'll need to inject in the marker.

@patak-cat

Copy link
Copy Markdown
Member Author

/ecosystem-ci run

@vite-ecosystem-ci

vite-ecosystem-ci Bot commented Jul 31, 2023

Copy link
Copy Markdown

📝 Ran ecosystem CI: Open

suite result
analogjs ❌ failure
astro ✅ success
histoire ❌ failure
iles ❌ failure
ladle ✅ success
laravel ✅ success
marko ✅ success
nuxt ✅ success
nx ❌ failure
previewjs ✅ success
qwik ✅ success
rakkas ✅ success
sveltekit ✅ success
unocss ✅ success
vite-plugin-pwa ✅ success
vite-plugin-ssr ✅ success
vite-plugin-react ✅ success
vite-plugin-react-pages ❌ failure
vite-plugin-react-swc ✅ success
vite-plugin-svelte ✅ success
vite-plugin-vue ✅ success
vite-setup-catalogue ✅ success
vitepress ✅ success
vitest ❌ failure

@patak-cat

Copy link
Copy Markdown
Member Author

Same CI fails as in main, merging

@patak-cat
patak-cat merged commit 488085d into main Jul 31, 2023
@patak-cat
patak-cat deleted the fix/module-preload-false branch July 31, 2023 09:52
fractalo added a commit to fractalo/twitch-chat-nexus that referenced this pull request Jan 1, 2024
vitejs/vite#13973
- above fix makes import.meta.glob to ignore 'modulePreload: false' option. so, css are preloaded by wrapper function and occurs error because wrapper function does not use chrome.runtime.getURL for css files.

- so, prevented dynamic import from being wrapped by vite preloader.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: build feat: css p3-minor-bug An edge case that only affects very specific usage (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build.modulePreload=false dynamic import css will lose

2 participants