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

feat(nuxt): namespace global variables for multi-app support #27263

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

Conversation

nicolaspayot
Copy link
Contributor

@nicolaspayot nicolaspayot commented May 17, 2024

🔗 Linked issue

2nd task of #21635. Also linked to #25336 although it doesn't completely remove window.__NUXT__.

📚 Description

This PR updates window.__NUXT__ global variable to handle multi-app payloads and config by storing the data under their appId.

Before:

window.__NUXT__ = { config: {...}, data: {...}, ...}

After:

window.__NUXT__ = {
  'nuxt-app-1': { config: {...}, data: {...}, ...} }
}

It also replaces scripts global IDs __NUXT_DATA__ and __NUXT_LOGS__ with data attributes:

Before:

<script type="application/json" id="__NUXT_DATA__">...</script>
<script type="application/json" id="__NUXT_LOGS__">...</script>

After:

<script type="application/json" data-nuxt-data="nuxt-app-1">...</script>
<script type="application/json" data-nuxt-logs="nuxt-app-1">...</script>

This will eventually allows the use of multiple Nuxt applications on a same page.

📝 To do:

Copy link

stackblitz bot commented May 17, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions bot added the 3.x label May 17, 2024
@nicolaspayot nicolaspayot changed the title Feat/nuxt/multi app global vars feat(nuxt): namespace global variables for multi-app support May 17, 2024
@nicolaspayot nicolaspayot force-pushed the feat/nuxt/multi-app-global-vars branch from f30a78c to b2ff8da Compare May 18, 2024 20:21
@@ -50,6 +50,7 @@ export default defineNuxtPlugin({
}
Object.assign(nuxtApp.payload, await nuxtApp.runWithContext(getNuxtClientPayload))
// For backwards compatibility - TODO: remove later
Copy link
Member

Choose a reason for hiding this comment

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

I'm still wondering if we have to set the payload here / why it was marked for compat only?

@danielroe danielroe mentioned this pull request May 30, 2024
2 tasks
@nicolaspayot nicolaspayot force-pushed the feat/nuxt/multi-app-global-vars branch from 404be61 to f2a86d2 Compare June 3, 2024 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants