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

fix(nuxt): avoid injecting url helpers into globalThis #9627

Merged
merged 5 commits into from
Jan 14, 2023

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Dec 9, 2022

πŸ”— Linked issue

resolves nuxt/nuxt#14372

❓ 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

On server-side, rather than declaring __buildAssetsURL and __publicAssetsURL on globalThis, this PR relies on nitro auto-imports to ensure they are injected where needed in the server app.

Note: We would need to ensure that the nitro auto-imports functionality cannot be turned off if we are relying on it in this context. See also nitrojs/nitro#742.

πŸ“ 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 Dec 9, 2022
@danielroe danielroe requested a review from pi0 December 9, 2022 15:53
@danielroe danielroe self-assigned this Dec 9, 2022
@codesandbox
Copy link

codesandbox bot commented Dec 9, 2022

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@danielroe danielroe changed the title fix(nuxt): avoid injecting url helpers into globalThis fix(nuxt)!: avoid injecting url helpers into globalThis Dec 9, 2022
@danielroe danielroe marked this pull request as draft December 9, 2022 18:31
@danielroe danielroe marked this pull request as ready for review December 9, 2022 22:39
@pi0
Copy link
Member

pi0 commented Dec 12, 2022

Although this will heal the issues similar to nuxt/nuxt#14372, both server and client instances are supposed to run in an isolated environment. I'm okay with such change since also helps with vercel-edge but I'm afraid it won't solve the multi-instance issue. Other things including hookable core depend on unique globalThis instance and it is shared.

// @ts-ignore
globalThis.__buildAssetsURL = buildAssetsURL
// @ts-ignore
globalThis.__publicAssetsURL = publicAssetsURL
Copy link
Member

Choose a reason for hiding this comment

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

I think we can keep injecting to globalThis as well

@@ -24,11 +24,11 @@ export async function buildServer (ctx: ViteBuildContext) {
return { relative: true }
}
if (type === 'public') {
return { runtime: `globalThis.__publicAssetsURL(${JSON.stringify(filename)})` }
return { runtime: `__publicAssetsURL(${JSON.stringify(filename)})` }
Copy link
Member

Choose a reason for hiding this comment

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

Then here we can conditionally render either with globalThis or without based on auto imports being enabled.

@danielroe danielroe requested a review from pi0 December 19, 2022 11:00
@vercel vercel bot temporarily deployed to Preview December 19, 2022 11:08 Inactive
@danielroe danielroe requested review from pi0 and removed request for pi0 January 14, 2023 00:24
@vercel vercel bot temporarily deployed to Preview January 14, 2023 00:31 Inactive
@danielroe danielroe changed the title fix(nuxt)!: avoid injecting url helpers into globalThis fix(nuxt): avoid injecting url helpers into globalThis Jan 14, 2023
@danielroe danielroe merged commit 488479a into main Jan 14, 2023
@danielroe danielroe deleted the refactor/global-url-helpers branch January 14, 2023 01:27
@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe mentioned this pull request Jan 20, 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.

Running 2 Nuxt handlers (different projects) in the same environment mixes static urls
2 participants