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

WIP: Add API for making it possible to block loading of SSR only static content components with vue-lazy-hydration #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maoberlehner
Copy link

So this is a very rough proof-of-concept of an API for vue-lazy-hydration to register static components that should not be prefetched and loaded on the client.

I'm aware that this probably can't be the final implementation of this but I'd be happy to get feedback and further improve the pull request!

In Nuxt 3 I made the following changes to make this work:

 // app/plugins/preload.server.ts
 export default <Plugin> function preload ({ app }) {
   app.mixin({
     beforeCreate () {
-      const { _registeredComponents } = this.$nuxt.ssrContext
-      const { __moduleIdentifier } = this.$options
-      _registeredComponents.push(__moduleIdentifier)
+      const { _registeredComponents, _staticComponents } = this.$nuxt.ssrContext
+      const { __moduleIdentifier, __lazyHydrationTiming } = this.$options

+      if (!__lazyHydrationTiming) {
+        _registeredComponents.push(__moduleIdentifier)
+      } else if (__lazyHydrationTiming === 'NEVER') {
+        _staticComponents.push(__moduleIdentifier)
+      }
     }
   })
 }

This adds the necessary API for vue-lazy-hydration to register static
components.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant