wip: provide hardcoded check to test delayed hydration runtime comp

This commit is contained in:
Michael Brevard 2024-04-08 17:19:59 +03:00 committed by GitHub
parent 66938bc152
commit 20a32b2200
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,7 +21,7 @@ export const loaderPlugin = createUnplugin((options: LoaderOptions) => {
const exclude = options.transform?.exclude || []
const include = options.transform?.include || []
const serverComponentRuntime = resolve(distDir, 'components/runtime/server-component')
const clientDelayedComponentRuntime = resolve(distDir, 'components/runtime/client-delayed-component')
return {
name: 'nuxt:components-loader',
enforce: 'post',
@ -72,9 +72,17 @@ export const loaderPlugin = createUnplugin((options: LoaderOptions) => {
}
if (lazy) {
// Temporary hardcoded check to verify runtime functionality
if (name === "DelayedWrapperTestComponent") {
imports.add(genImport(clientDelayedComponentRuntime, [{ name: 'createLazyIOClientPage' }]))
imports.add(`const ${identifier} = createLazyIOClientPage(${JSON.stringify(name)})`)
identifier += '_delayedIO'
}
else {
imports.add(genImport('vue', [{ name: 'defineAsyncComponent', as: '__defineAsyncComponent' }]))
identifier += '_lazy'
imports.add(`const ${identifier} = __defineAsyncComponent(${genDynamicImport(component.filePath, { interopDefault: false })}.then(c => c.${component.export ?? 'default'} || c)${isClientOnly ? '.then(c => createClientOnly(c))' : ''})`)
}
} else {
imports.add(genImport(component.filePath, [{ name: component._raw ? 'default' : component.export, as: identifier }]))