fix(nuxt): ensure prerendered components are treated as islands (#21583)

This commit is contained in:
Daniel Roe 2023-06-16 15:47:59 +01:00 committed by GitHub
parent c73bed8c6d
commit 2a42a5f807
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -79,6 +79,7 @@ export default defineComponent({
} }
// TODO: Validate response // TODO: Validate response
const result = await $fetch<NuxtIslandResponse>(url, { const result = await $fetch<NuxtIslandResponse>(url, {
responseType: 'json',
params: { params: {
...props.context, ...props.context,
props: props.props ? JSON.stringify(props.props) : undefined props: props.props ? JSON.stringify(props.props) : undefined

View File

@ -20,7 +20,10 @@ if (componentIslands) {
revivers.Island = ({ key, params }: any) => { revivers.Island = ({ key, params }: any) => {
const nuxtApp = useNuxtApp() const nuxtApp = useNuxtApp()
if (!nuxtApp.isHydrating) { if (!nuxtApp.isHydrating) {
nuxtApp.payload.data[key] = nuxtApp.payload.data[key] || $fetch(`/__nuxt_island/${key}`, params ? { params } : {}).then((r) => { nuxtApp.payload.data[key] = nuxtApp.payload.data[key] || $fetch(`/__nuxt_island/${key}`, {
responseType: 'json',
...params ? { params } : {}
}).then((r) => {
nuxtApp.payload.data[key] = r nuxtApp.payload.data[key] = r
return r return r
}) })