1
0
mirror of https://github.com/nuxt/nuxt.git synced 2025-02-28 05:33:46 +00:00

fix: only enable delayed hydration with the experimental flag

This commit is contained in:
Michael Brevard 2024-06-03 10:22:52 +03:00 committed by GitHub
parent e0a2f219db
commit 2f2cb8e0cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -41,13 +41,13 @@ export const loaderPlugin = createUnplugin((options: LoaderOptions) => {
const imports = new Set<string>() const imports = new Set<string>()
const map = new Map<Component, string>() const map = new Map<Component, string>()
const s = new MagicString(code) const s = new MagicString(code)
const nuxt = tryUseNuxt()
// replace `_resolveComponent("...")` to direct import // replace `_resolveComponent("...")` to direct import
s.replace(/(?<=[ (])_?resolveComponent\(\s*["'](lazy-|Lazy)?(Idle|Visible|idle-|visible-)?([^'"]*)["'][^)]*\)/g, (full: string, lazy: string, modifier: string, name: string) => { s.replace(/(?<=[ (])_?resolveComponent\(\s*["'](lazy-|Lazy)?(Idle|Visible|idle-|visible-)?([^'"]*)["'][^)]*\)/g, (full: string, lazy: string, modifier: string, name: string) => {
const component = findComponent(components, name, options.mode) const component = findComponent(components, name, options.mode)
if (component) { if (component) {
// @ts-expect-error TODO: refactor to nuxi // @ts-expect-error TODO: refactor to nuxi
if (component._internal_install && tryUseNuxt()?.options.test === false) { if (component._internal_install && nuxt?.options.test === false) {
// @ts-expect-error TODO: refactor to nuxi // @ts-expect-error TODO: refactor to nuxi
import('../core/features').then(({ installNuxtModule }) => installNuxtModule(component._internal_install)) import('../core/features').then(({ installNuxtModule }) => installNuxtModule(component._internal_install))
} }
@ -72,7 +72,7 @@ export const loaderPlugin = createUnplugin((options: LoaderOptions) => {
} }
if (lazy) { if (lazy) {
if (modifier) { if (nuxt?.options.experimental.componentLazyHydration === true && modifier) {
switch (modifier) { switch (modifier) {
case 'Visible': case 'Visible':
case 'visible-': case 'visible-':