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

refactor(nuxt): add additional flag to enable remote sources #22409

Merged
merged 3 commits into from Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/nuxt/src/app/components/nuxt-island.ts
Expand Up @@ -13,6 +13,9 @@ import { getFragmentHTML, getSlotProps } from './utils'
import { useNuxtApp, useRuntimeConfig } from '#app/nuxt'
import { useRequestEvent } from '#app/composables/ssr'

// @ts-expect-error virtual file
import { remoteComponentIslands } from '#build/nuxt.config.mjs'

const pKey = '_islandPromises'
const SSR_UID_RE = /nuxt-ssr-component-uid="([^"]*)"/
const UID_ATTR = /nuxt-ssr-component-uid(="([^"]*)")?/
Expand Down Expand Up @@ -106,7 +109,7 @@ export default defineComponent({
const key = `${props.name}_${hashId.value}`
if (nuxtApp.payload.data[key] && !force) { return nuxtApp.payload.data[key] }

const url = props.source ? new URL(`/__nuxt_island/${key}`, props.source).href : `/__nuxt_island/${key}`
const url = remoteComponentIslands && props.source ? new URL(`/__nuxt_island/${key}`, props.source).href : `/__nuxt_island/${key}`

if (process.server && process.env.prerender) {
// Hint to Nitro to prerender the island component
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/src/components/module.ts
Expand Up @@ -221,7 +221,7 @@ export default defineNuxtModule<ComponentsOptions>({
getComponents,
mode,
transform: typeof nuxt.options.components === 'object' && !Array.isArray(nuxt.options.components) ? nuxt.options.components.transform : undefined,
experimentalComponentIslands: nuxt.options.experimental.componentIslands
experimentalComponentIslands: !!nuxt.options.experimental.componentIslands
}))

if (isServer && nuxt.options.experimental.componentIslands) {
Expand Down Expand Up @@ -265,7 +265,7 @@ export default defineNuxtModule<ComponentsOptions>({
getComponents,
mode,
transform: typeof nuxt.options.components === 'object' && !Array.isArray(nuxt.options.components) ? nuxt.options.components.transform : undefined,
experimentalComponentIslands: nuxt.options.experimental.componentIslands
experimentalComponentIslands: !!nuxt.options.experimental.componentIslands
}))

if (nuxt.options.experimental.componentIslands && mode === 'server') {
Expand Down
1 change: 1 addition & 0 deletions packages/nuxt/src/core/templates.ts
Expand Up @@ -329,6 +329,7 @@ export const nuxtConfigTemplate = {
...Object.entries(ctx.nuxt.options.app).map(([k, v]) => `export const ${camelCase('app-' + k)} = ${JSON.stringify(v)}`),
`export const renderJsonPayloads = ${!!ctx.nuxt.options.experimental.renderJsonPayloads}`,
`export const componentIslands = ${!!ctx.nuxt.options.experimental.componentIslands}`,
`export const remoteComponentIslands = ${ctx.nuxt.options.experimental.componentIslands === 'local+remote'}`,
`export const devPagesDir = ${ctx.nuxt.options.dev ? JSON.stringify(ctx.nuxt.options.dir.pages) : 'null'}`,
`export const devRootDir = ${ctx.nuxt.options.dev ? JSON.stringify(ctx.nuxt.options.rootDir) : 'null'}`
].join('\n\n')
Expand Down
9 changes: 8 additions & 1 deletion packages/schema/src/config/experimental.ts
Expand Up @@ -137,8 +137,15 @@ export default defineUntypedSchema({

/**
* Experimental component islands support with <NuxtIsland> and .island.vue files.
* @type {true | 'local' | 'local+remote' | false}
*/
componentIslands: false,
componentIslands: {
$resolve: (val) => {
if (typeof val === 'string') { return val }
if (val === true) { return 'local' }
return false
}
},

/**
* Config schema support
Expand Down