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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

huang-julien
Copy link
Contributor

πŸ”— 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

@@ -125,7 +125,7 @@ async function _loadUserConfig(
});
if (preset) {
return {
config: preset,
config: defu(preset),
Copy link
Member

@pi0 pi0 Jan 8, 2025

Choose a reason for hiding this comment

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

defu is not safe as a clone utility. we might need to use klona.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha i think @danielroe would be interested to see that :D . Why isn't it safe ?

I'll change move it to klona 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