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?

@nicolaspayot nicolaspayot force-pushed the feat/nuxt/multi-app-global-vars branch from b2ff8da to 2c3f046 Compare May 22, 2024 07:39
@nicolaspayot nicolaspayot marked this pull request as ready for review May 22, 2024 13:35
@@ -409,6 +409,7 @@ export const nuxtConfigTemplate: NuxtTemplate = {
`export const vueAppRootContainer = ${ctx.nuxt.options.app.rootId ? `'#${ctx.nuxt.options.app.rootId}'` : `'body > ${ctx.nuxt.options.app.rootTag}'`}`,
`export const viewTransition = ${ctx.nuxt.options.experimental.viewTransition}`,
`export const appId = ${JSON.stringify(ctx.nuxt.options.appId)}`,
`export const multiApp = ${!!ctx.nuxt.options.future.multiApp}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that there are better and more explicit for this variable, eg: runningMultipleApp, usingMultipleApp.

Imo the current name is easy to be misleading to end users, and maybe also module developers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. runningMultiApp sounds good to me. What do you think?

@danielroe danielroe mentioned this pull request May 30, 2024
2 tasks
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