framework icon indicating copy to clipboard operation
framework copied to clipboard

feat(nuxt): config default keepalive, page & layout transitions

Open danielroe opened this issue 2 years ago • 1 comments

🔗 Linked issue

resolves #5729

❓ Type of change

  • [ ] 📖 Documentation (updates to the documentation or readme)
  • [ ] 🐞 Bug fix (a non-breaking change that fixes an issue)
  • [x] 👌 Enhancement (improving an existing functionality like performance)
  • [ ] ✨ New feature (a non-breaking change that adds functionality)
  • [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This allows support for configuring page & layout transition default values, as well as keepalive. (Otherwise there is the tedious task of doing so for every individual file.)

In order to do this, we now inject #build/app.config.mjs to automatically expose all values within the app key in Nuxt config, rather than creating ever-more virtual files for particular use-cases. (We would, for example, have had to do this for layouts and page transitions separately otherwise.) This means we were able to drop meta.config.mjs and in general is a useful pattern for future app configuration.

📝 Checklist

  • [x] I have linked an issue or discussion.
  • [x] I have updated the documentation accordingly.

danielroe avatar Jul 12 '22 15:07 danielroe

Deploy Preview for nuxt3-docs canceled.

Name Link
Latest commit a414fcd4765f7cd816337908bc95ea81ec244eea
Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/6304c375fa5ce1000818a2af

netlify[bot] avatar Jul 12 '22 15:07 netlify[bot]

Thanks for rebasing. Shall we type appConfig.nuxt from schema now?

pi0 avatar Aug 22 '22 15:08 pi0

Beautiful work @danielroe ❤️

Shall we document more to use app.config.ts for such configurations from now on?

atinux avatar Aug 22 '22 15:08 atinux

Shall we document more to use app.config.ts for such configurations from now on?

Currently, usage of useAppConfig().nuxt is kinda internal. For some, we might have built-time optimization opportunities (like not bundling transition bytes) while if we make users able to set via app.config, we cannot do this anymore as such config can be changed on runtime. I suggest not adding nuxt types from AppConfigInput as well for this PR (keep marking it as never for input but typing for AppConfig)

pi0 avatar Aug 22 '22 15:08 pi0

(fixture seems broken)

pi0 avatar Aug 22 '22 16:08 pi0

Could we take this opportunity to also give the possibility to set those values to false to disable keepalive, page & layout transitions?

atinux avatar Aug 23 '22 10:08 atinux

Indeed, that is one of the key use-cases of this PR. As implemented here, it is possible to set them to false and it will disable keepalive, page & layout transitions.

danielroe avatar Aug 23 '22 10:08 danielroe

Thinking more about approaches, i think for specific nuxt bundled config, using an internal template with named exports (#build/nuxt.config.mjs ?) could be safer since we probably don't need nor could support HMR for these configs originating from nuxt.config and it makes it consistent with feature plans being able to treeshake at build time (appConfig is totally runtime-dynamic. we cannot depend on it for this unless passing another build flag)

pi0 avatar Aug 23 '22 10:08 pi0

Okay - so just to confirm, we'll refactor back to original approach of this PR, but using nuxt.config.mjs filename?

danielroe avatar Aug 23 '22 10:08 danielroe