Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: modulePreload false #13973

Merged
merged 2 commits into from
Jul 31, 2023
Merged

fix: modulePreload false #13973

merged 2 commits into from
Jul 31, 2023

Conversation

patak-dev
Copy link
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

@stackblitz
Copy link

stackblitz bot commented Jul 28, 2023

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

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

@bluwy bluwy left a comment

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.

packages/vite/src/node/plugins/importAnalysisBuild.ts Outdated Show resolved Hide resolved
@patak-dev
Copy link
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-dev
Copy link
Member Author

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

vite-ecosystem-ci bot commented Jul 31, 2023

📝 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-dev
Copy link
Member Author

Same CI fails as in main, merging

@patak-dev patak-dev merged commit 488085d into main Jul 31, 2023
@patak-dev patak-dev 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