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: skip the plugin if it has been called before with the same id and importer #19016

Conversation

sapphi-red
Copy link
Member

Description

#18903 changed the skipSelf behavior to align with rollup.
In Nuxt + Vitest scenario, a recursive call happened because of that change (it happens with rollup: rollup/rollup#5768).

Nuxt has nuxt:resolve-bare-imports plugin that calls this.resolve(id, nuxtRoot) and Vitest has vitest:resolve-core plugin that calls this.resolve(id, viteIndexHtml).
These plugins were calling each other after #18903.
This didn't happen before #18903 because the plugins were skipped even if the importer is different.

In this PR, this.resolve(id, importer) with the same id and importer will be skipped when it's called inside the same id and importer even if it's called inside a different this.resolve.
For example, this.resolve('foo', 'bar') -> this.resolve('foo', 'bar') was skipped before this PR. this.resolve('foo', 'bar') -> this.resolve('foo', 'bar2') -> this.resolve('foo', 'bar') was not skipped before this PR, but now this case is also skipped.

fixes this CI failure in nuxt: https://github.com/nuxt/nuxt/actions/runs/12418711683/job/34672477920?pr=30306
refs #18903

@sapphi-red sapphi-red added the p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) label Dec 20, 2024
patak-dev
patak-dev previously approved these changes Dec 20, 2024
Comment on lines +589 to +593
if (sameCallIndex !== -1) {
skipCallsTemp[sameCallIndex] = {
...skipCallsTemp[sameCallIndex],
called: true,
}
Copy link
Collaborator

@hi-ogawa hi-ogawa Dec 20, 2024

Choose a reason for hiding this comment

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

Awesome investigation!
The fix looks good to merge, but while trying to understand the logic, I cannot tell why we cannot immediately do return null for such call as this seems to be destined to go resolve loop.
The new test case seems to pass with "just return null". Do you have a case such approach fails?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a test case that fails with return null: 67c4a66

Copy link
Collaborator

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

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

Thanks!
Call flow is still mind bending to me, but I'll try to understand this in a different time 😅

danielroe added a commit to nuxt/nuxt that referenced this pull request Dec 23, 2024
danielroe added a commit to nuxt/nuxt that referenced this pull request Dec 23, 2024
@patak-dev patak-dev merged commit b178c90 into vitejs:main Jan 2, 2025
15 checks passed
patak-dev pushed a commit that referenced this pull request Jan 2, 2025
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Jan 3, 2025
| datasource | package | from  | to    |
| ---------- | ------- | ----- | ----- |
| npm        | vite    | 6.0.6 | 6.0.7 |


## [v6.0.7](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small607-2025-01-02-small)

-   fix: fix `minify` when `builder.sharedPlugins: true` ([#19025](vitejs/vite#19025)) ([f7b1964](vitejs/vite@f7b1964)), closes [#19025](vitejs/vite#19025)
-   fix: skip the plugin if it has been called before with the same id and importer ([#19016](vitejs/vite#19016)) ([b178c90](vitejs/vite@b178c90)), closes [#19016](vitejs/vite#19016)
-   fix(html): error while removing `vite-ignore` attribute for inline script ([#19062](vitejs/vite#19062)) ([a492253](vitejs/vite@a492253)), closes [#19062](vitejs/vite#19062)
-   fix(ssr): fix semicolon injection by ssr transform ([#19097](vitejs/vite#19097)) ([1c102d5](vitejs/vite@1c102d5)), closes [#19097](vitejs/vite#19097)
-   perf: skip globbing for static path in warmup ([#19107](vitejs/vite#19107)) ([677508b](vitejs/vite@677508b)), closes [#19107](vitejs/vite#19107)
-   feat(css): show lightningcss warnings ([#19076](vitejs/vite#19076)) ([b07c036](vitejs/vite@b07c036)), closes [#19076](vitejs/vite#19076)
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Jan 4, 2025
| datasource | package | from  | to    |
| ---------- | ------- | ----- | ----- |
| npm        | vite    | 6.0.6 | 6.0.7 |


## [v6.0.7](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small607-2025-01-02-small)

-   fix: fix `minify` when `builder.sharedPlugins: true` ([#19025](vitejs/vite#19025)) ([f7b1964](vitejs/vite@f7b1964)), closes [#19025](vitejs/vite#19025)
-   fix: skip the plugin if it has been called before with the same id and importer ([#19016](vitejs/vite#19016)) ([b178c90](vitejs/vite@b178c90)), closes [#19016](vitejs/vite#19016)
-   fix(html): error while removing `vite-ignore` attribute for inline script ([#19062](vitejs/vite#19062)) ([a492253](vitejs/vite@a492253)), closes [#19062](vitejs/vite#19062)
-   fix(ssr): fix semicolon injection by ssr transform ([#19097](vitejs/vite#19097)) ([1c102d5](vitejs/vite@1c102d5)), closes [#19097](vitejs/vite#19097)
-   perf: skip globbing for static path in warmup ([#19107](vitejs/vite#19107)) ([677508b](vitejs/vite@677508b)), closes [#19107](vitejs/vite#19107)
-   feat(css): show lightningcss warnings ([#19076](vitejs/vite#19076)) ([b07c036](vitejs/vite@b07c036)), closes [#19076](vitejs/vite#19076)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants