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

Auto imported component's style is loaded even if I don't use component #12801

Closed
jd-solanki opened this issue Nov 18, 2021 · 19 comments · Fixed by nuxt/framework#2067
Closed
Assignees

Comments

@jd-solanki
Copy link
Contributor

Environment

- Operating System: `Darwin`
- Node Version:     `v16.13.0`
- Nuxt Version:     `3.0.0-27274229.29599f0`
- Package Manager:  `yarn@1.22.17`
- Bundler:          `Vite`
- User Config:      `alias`, `buildModules`, `css`, `vite`
- Runtime Modules:  `-`
- Build Modules:    `@vueuse/core/nuxt@6.8.0`, `unplugin-icons/nuxt`, `~/@core/layouts/nuxt`

Reproduction

https://codesandbox.io/s/determined-sky-77qrl?file=/app.vue:19-43

Describe the bug

Nuxt 3 docs state "It will automatically import the components only if used".

Does components placed inside component dir is registered globally?

If the component is only get imported then why style is loaded even if the component is not used.

In this codesandbox: https://codesandbox.io/s/determined-sky-77qrl?file=/app.vue:19-43

I don't use the custom button component but still, the style from that component is loaded? 🤔

Additional context

No response

Logs

No response

@productdevbook
Copy link
Sponsor Member

some problem

CleanShot_2021-11-18_at_14 16 33

@pi0
Copy link
Member

pi0 commented Nov 18, 2021

/cc @antfu. I think issue is that styles are eagerly loaded for lazy imported components

@antfu antfu self-assigned this Nov 18, 2021
@antfu
Copy link
Member

antfu commented Nov 18, 2021

Is this only happens on dev?

@productdevbook
Copy link
Sponsor Member

Is this only happens on dev?

@antfu no, dev + (build + start) two problem

@productdevbook
Copy link
Sponsor Member

productdevbook commented Nov 19, 2021

some vue component 4 copy add header :D
CleanShot 2021-11-19 at 20 22 36@2x

CleanShot 2021-11-19 at 20 23 20@2x

@antfu
Copy link
Member

antfu commented Nov 30, 2021

Bring back by nuxt/framework#2227

@antfu antfu reopened this Nov 30, 2021
@psycongaroo
Copy link
Contributor

bump
any news about that?

@pi0
Copy link
Member

pi0 commented Jul 15, 2022

/cc @antfu

@danielroe
Copy link
Member

Also see #13778.

@HochinChan
Copy link

HochinChan commented Aug 18, 2022

Are there any solutions? I had the same problem.😭

image

@danielroe
Copy link
Member

@HochinChan Your situation is not related, I think. I would recommend not using global components for exactly these kind of performance reasons, but instead to rely on Nuxt to auto-import them where required. You can track #14584 for more prefetching improvements.

@danielroe
Copy link
Member

Reproduction with latest Nuxt: https://stackblitz.com/edit/github-nd6mk4.

@HochinChan
Copy link

Reproduction with latest Nuxt: https://stackblitz.com/edit/github-nd6mk4.

https://stackblitz.com/edit/nuxt-starter-eyapnx

When I access pages/index (without using any components), the styles of all the components and the styles of other pages are also loaded

image

@danielroe
Copy link
Member

That should no longer be the case for pages on the edge channel, but yes, that was the purpose of my reproduction link - to show the issue.

@HochinChan
Copy link

That should no longer be the case for pages on the edge channel, but yes, that was the purpose of my reproduction link - to show the issue.

Sorry, I'm not quite sure what you mean, but I was wondering how to make it load only the style of the current page

@danielroe
Copy link
Member

Use https://v3.nuxtjs.org/guide/going-further/edge-channel. See nuxt/framework#6662. It will still load component styles; that's what this issue is about. But it won't load page styles.

@HochinChan
Copy link

Use https://v3.nuxtjs.org/guide/going-further/edge-channel. See nuxt/framework#6662. It will still load component styles; that's what this issue is about. But it won't load page styles.

I see, thanks. The other page styles won't load when I use @latest.

@pi0
Copy link
Member

pi0 commented Aug 23, 2022

We are working to make preload/prefetch smarter. Let's track the issue of global components in #14675. If there is any extra prefetch/preloading issue not caused by usage of global components please make another new issue with reproduction 🙏🏼

@pi0 pi0 closed this as completed Aug 23, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants