Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(vite): dedupe vue in client bundle #6735

Merged
merged 3 commits into from
Aug 18, 2022
Merged

fix(vite): dedupe vue in client bundle #6735

merged 3 commits into from
Aug 18, 2022

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Aug 18, 2022

πŸ”— Linked issue

resolves nuxt/nuxt#14625, also see nuxt/nuxt#13632

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This enables vite's dedupe functionality for vue, where we definitely want to ensure we have a single instance bundled. A previous issue with this plugin (where it emitted CJS code) seems to have been resolved in Vite 3.

Edit: enabling only for client.

It injects the following code in the server bundle:

https://github.com/vitejs/vite/blob/9e9cd23763c96020cdf1807334368e038f61ad01/packages/vite/src/node/plugins/ssrRequireHook.ts#L53-L71

We can alternatively enable this only for the client bundle. WDYT @pi0?

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroe danielroe added enhancement New feature or request vite labels Aug 18, 2022
@danielroe danielroe requested a review from pi0 August 18, 2022 07:49
@danielroe danielroe self-assigned this Aug 18, 2022
@netlify
Copy link

netlify bot commented Aug 18, 2022

βœ… Deploy Preview for nuxt3-docs canceled.

Name Link
πŸ”¨ Latest commit 8a73621
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/62fdf1f2951c71000862ef8d

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

seems a good option to try

@pi0
Copy link
Member

pi0 commented Aug 18, 2022

Just checked SSR plugin. It seems modifying Node.js Module behavior. Probably safer to enable for client bundle only. Nitro should properly does it.

@pi0 pi0 changed the title feat(vite): dedupe vue by default fix(vite): dedupe vue in client bundle Aug 18, 2022
@pi0 pi0 merged commit faf00f5 into main Aug 18, 2022
@pi0 pi0 deleted the fix/dedupe-vue branch August 18, 2022 08:06
@danielroe
Copy link
Member Author

Putting this here for future reference: vitejs/vite#7454 (comment)

@pi0 pi0 mentioned this pull request Aug 26, 2022
haoqunjiang added a commit to haoqunjiang/vite that referenced this pull request Nov 22, 2022
Fixes vitejs#2443
Fixes vitejs#7454

It's already been set by default in Nuxt 3 for a while now nuxt/framework#6735
So I think this change should be harmless.
And technically it could be considered a fix than a feat.

Nevertheless, it's better to ship it in v4 to minimize disruptions on
the user side.

Things that are not covered in this PR:
1. SSR, because `resolve.dedupe` doesn't work for ESM build outputs, and
the CommonJS version is kinda hacky, I think it's better to skip the
config for SSR completely. Besides, most related issues are from the
client side.
2. #5958 isn't fixed by this PR.
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.x enhancement New feature or request vite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slots break extend, if extend-folder is side by side with project-folder
2 participants