-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat(nuxt): support deep: false
for data composables
#23600
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
Conversation
|
β Live Preview ready!
|
What do you think about doing something like |
I think it's less clear about our intentions, default should be keep for default data, here it's more like |
data: ref(getCachedData() ?? options.default!()), | ||
data: options.shallow | ||
? shallowRef(getCachedData() ?? options.default!()) | ||
: ref(getCachedData() ?? options.default!()), | ||
pending: ref(!hasCachedData()), | ||
error: toRef(nuxt.payload._errors, key), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could probably always return error in a shallowRef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a toShallowRef
here, but yes it worth it here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could create a local util until/if it's available in core
Co-authored-by: Julien Huang <julien.h.dev@gmail.com>
Co-authored-by: Daniel Roe <daniel@roe.dev>
name: 'nuxt:async-data-shallow', | ||
enforce: 'pre', | ||
setup (nuxtApp) { | ||
nuxtApp._asyncDataShallow = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use nuxt.config.mjs
instead?
nuxt/packages/nuxt/src/core/templates.ts
Lines 338 to 353 in a2fb823
export const nuxtConfigTemplate = { | |
filename: 'nuxt.config.mjs', | |
getContents: (ctx: TemplateContext) => { | |
return [ | |
...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 payloadExtraction = ${!!ctx.nuxt.options.experimental.payloadExtraction}`, | |
`export const appManifest = ${!!ctx.nuxt.options.experimental.appManifest}`, | |
`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'}`, | |
`export const vueAppRootContainer = ${ctx.nuxt.options.app.rootId ? `'#${ctx.nuxt.options.app.rootId}'` : `'body > ${ctx.nuxt.options.app.rootTag}'`}` | |
].join('\n\n') | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's defer this to another PR
shallow
option to useAsyncData
and useFetch
deep: false
for data composables
resolves #12406
β Type of change
π Description
This adds new option to control output of
useAsyncData
anduseFetch
data in order to haveShallowRef
instead ofRef
It also introduces a new experimental flag
asyncDataShallow
to change the default behavior to useshallow
by defaultπ Checklist