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

build.modulePreload=false dynamic import css will lose #10773

Closed
7 tasks done
alasq opened this issue Nov 3, 2022 · 8 comments · Fixed by #13973
Closed
7 tasks done

build.modulePreload=false dynamic import css will lose #10773

alasq opened this issue Nov 3, 2022 · 8 comments · Fixed by #13973
Labels
feat: build feat: css p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@alasq
Copy link

alasq commented Nov 3, 2022

Describe the bug

build.modulePreload=false
This config should config preload css only,not delete module dependence

Reproduction

https://stackblitz.com/edit/vitejs-vite-u8njgy?file=main.js,style.js,vite.config.js&terminal=dev

Steps to reproduce

  1. npm run dev

  2. click "click me" button

  3. the background-color will be red

  4. npm run preview

  5. click "click me" button

  6. the background-color will not be red

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    vite: ^3.2.1 => 3.2.2

Used Package Manager

npm

Logs

No response

Validations

@li-yechao

This comment was marked as spam.

@macbem
Copy link

macbem commented Jan 4, 2023

I've also encountered this. It also happens if CSS is imported synchronously from a dynamic JS import.

@jiadesen

This comment was marked as spam.

@alasq
Copy link
Author

alasq commented Jan 11, 2023

why i use build.modulePreload=false ? If modulePreload=true, js modulePreload request will missing http header referer in Google Chrome. But firefox not! My company server settings is valid referer. js resource will response http 401 error.

You can try this code in html
<link as="script" rel="modulepreload" href="xxx.js"> referer is ok!
But you use script create this like document.head.insertAdjacentHTML('beforeend','<link as="script" rel="modulepreload" href="xxx.js">') referer is missing!
Vite create modulePreload link by script like latter. So referer miss.

This is Google Chrome BUG ??

@dajvweizhong
Copy link

image
vite 动态引入 css 和 modulepreload 用的是同一个方法,估计这也是为啥关闭 modulePreload 之后样式丢失的原因(我猜测的,没有仔细看 modulePreload 为 false 那块的逻辑)。
如果只是想把 js 的 preload 关掉的话,可以参考:(简单验证了下成功了,是否会引入其他问题目前未知)
image

@daniele-orlando
Copy link

Is there any progress on this bug?

@patak-dev
Copy link
Member

There is a PR now to fix this one at #13973

meta: @daniele-orlando please avoid sending "Any updates?" messages to issues in the future 🙏🏼
If you see an issue that hasn't been worked on, there are no updates. You can help it move forward by working on a PR or helping debug where is the problem.
When there are updates, contributors send messages to the issues or PRs about their progress.

@daniele-orlando
Copy link

Understood. Sorry for the silly question. 😓

@github-actions github-actions bot locked and limited conversation to collaborators Aug 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: build feat: css p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants