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

fix(nuxt): ensure component helper methods do not create side-effects #6789

Merged
merged 1 commit into from
Aug 22, 2022

Conversation

danielroe
Copy link
Member

πŸ”— Linked issue

resolves nuxt/nuxt#14650

❓ 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

Lazy components (defined with defineAsyncComponent) were marked as having a side effect, so were persisting into the routes bundle. We should certainly not be including async component statements within the entry bundle, which also had the effect of marking them as dependencies of the entry rather than the page they correspond to (resulting in over-prefetching - see nuxt/nuxt#14584).


Note that I encountered this when debugging what I believe to be an upstream rollup bug that I'm still looking into, which is difficult to reproduce but essentially boils down to two modules which each contain:

defineAsyncComponent(() => __vitePreload(() => import('./Text.3d3cd0e1.js'),true?"__VITE_PRELOAD__":void 0,import.meta.url));
const meta = undefined;

being transformed into:

defineAsyncComponent(() => __vitePreload(() => import('./Text.3d3cd0e1.js'),true?"__VITE_PRELOAD__":void 0,import.meta$1.url));
const meta$1 = undefined;

defineAsyncComponent(() => __vitePreload(() => import('./Text.3d3cd0e1.js'),true?"__VITE_PRELOAD__":void 0,import.meta.url));
const meta = undefined;

(This seems like an over-zealous search + replace on the part of rollup.)

πŸ“ Checklist

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

@danielroe danielroe added bug Something isn't working πŸ”¨ p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage labels Aug 19, 2022
@danielroe danielroe requested a review from pi0 August 19, 2022 22:16
@danielroe danielroe self-assigned this Aug 19, 2022
@netlify
Copy link

netlify bot commented Aug 19, 2022

βœ… Deploy Preview for nuxt3-docs canceled.

Name Link
πŸ”¨ Latest commit 0ac4ae6
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/63000ba7525707000946529a

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.

Nice find!!

@pi0 pi0 merged commit 80abca9 into main Aug 22, 2022
@pi0 pi0 deleted the fix/component-side-effects branch August 22, 2022 08:50
@pi0 pi0 mentioned this pull request Aug 26, 2022
@simirka
Copy link

simirka commented Sep 5, 2022

@danielroe Hey, I am not sure if this is something on my side or after the new changes.
But after upgrading to a new rc.9 I am having this error, on the rc.8 all is working.

Expected "meta" but found "meta$k"
13877|
13878|  defineAsyncComponent(() =>
13879|      __vitePreload(() => import('./Test.0f9d27a0.js'),true?"__VITE_PRELOAD__":void 0,import.meta$k.url)
13881|  const meta$k = {
``

@danielroe
Copy link
Member Author

@simirka can you create a minimal reproduction?

@simirka
Copy link

simirka commented Sep 6, 2022

@danielroe Try to build it
https://codesandbox.io/s/suspicious-cherry-pqq6ci?file=/pages/test.vue

Attaching screenshot
image

@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 bug Something isn't working πŸ”¨ p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expected "meta" but found "meta$1" - rollup error with dynamic imports
3 participants