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(loader): clone preset object #2983

Merged
merged 6 commits into from
Jan 9, 2025
Merged

Conversation

huang-julien
Copy link
Contributor

@huang-julien huang-julien commented Jan 8, 2025

πŸ”— Linked issue

nuxt/test-utils#537
nuxt/test-utils#1043 ?

❓ Type of change

Hi πŸ‘‹

This PR fix an issue with presets and will allow multiple Nuxt to be ran within the same process (like for vitest workspaces or its vscode extension)

Linked issues above are trying to run multiple nuxt at the same time. It means we need also to be able to start multiple nitro.

Here's the race condition.

Presets are objects and

config: preset,

returns directly the reference of the preset.

If we load 2 nitro at the same time, C12 can delete _layers on the preset object
https://github.com/unjs/c12/blob/67cf916ca727e584390196ce3d3bfb76aa102ec1/src/loader.ts#L267
and the other other may need _layer at that time (calling .push() for example) which will fail and throw an error.

(will this pr be merge in nitro 2 or does it need another pr ? )

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 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)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

πŸ“ Checklist

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

@pi0
Copy link
Member

pi0 commented Jan 8, 2025

We should rebase it to v2

src/core/config/loader.ts Outdated Show resolved Hide resolved
@pi0
Copy link
Member

pi0 commented Jan 9, 2025

@huang-julien can you please rebase your PR against v2 branch?

@huang-julien huang-julien changed the base branch from main to v2 January 9, 2025 10:54
src/core/config/loader.ts Outdated Show resolved Hide resolved
src/core/config/loader.ts Outdated Show resolved Hide resolved
@pi0 pi0 merged commit 7281809 into nitrojs:v2 Jan 9, 2025
4 checks passed
@pi0
Copy link
Member

pi0 commented Jan 9, 2025

@huang-julien Thanks for PR. as this change adds runtime cost (and there is no easy way to reproduce/confirm with nitro only) can you please try on nightly channel if it actually solved linked issues?

@huang-julien
Copy link
Contributor Author

huang-julien commented Jan 9, 2025

Thanks for merging this so fast ❀️

https://github.com/nuxt/nuxt/tree/repro/nitro-preset-shared-object here's the branch for reproduction in Nuxt. You need to run npx jiti ./loadNuxt.ts in test/fixtures/multiple-nuxt

It doesn't solve linked issues but allows to create the PR that will solve them in Nuxt.

@pi0
Copy link
Member

pi0 commented Jan 9, 2025

That's a Nuxt reproduction. it was generally good safety fix thanks ❀️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants