ソースを参照

fix(vapor): expose async component alias for SSR runtime

daiwei 1 週間 前
コミット
9f6a215b8a

+ 0 - 38
packages/compiler-sfc/__tests__/compileScript.spec.ts

@@ -1792,41 +1792,3 @@ describe('compileScript', () => {
     expect(scriptAst).not.toBeDefined()
   })
 })
-
-describe('vapor mode + ssr', () => {
-  test('rewrite defineVaporAsyncComponent import', () => {
-    const { content } = compile(
-      `
-        <script setup vapor>
-        import { defineVaporAsyncComponent } from 'vue'
-        </script>
-      `,
-      {
-        templateOptions: {
-          ssr: true,
-        },
-      },
-    )
-    expect(content).toContain(
-      `import { defineAsyncComponent as defineVaporAsyncComponent } from 'vue'`,
-    )
-  })
-
-  test('rewrite defineVaporAsyncComponent import with local name', () => {
-    const { content } = compile(
-      `
-        <script setup vapor>
-        import { defineVaporAsyncComponent as def } from 'vue'
-        </script>
-      `,
-      {
-        templateOptions: {
-          ssr: true,
-        },
-      },
-    )
-    expect(content).toContain(
-      `import { defineAsyncComponent as def } from 'vue'`,
-    )
-  })
-})

+ 0 - 16
packages/compiler-sfc/src/compileScript.ts

@@ -393,22 +393,6 @@ export function compileScript(
         const imported = getImportedName(specifier)
         const source = node.source.value
 
-        // rewrite defineVaporAsyncComponent import to defineAsyncComponent
-        // in SSR + Vapor mode
-        if (
-          vapor &&
-          ssr &&
-          specifier.type === 'ImportSpecifier' &&
-          source === 'vue' &&
-          imported === 'defineVaporAsyncComponent'
-        ) {
-          ctx.s.overwrite(
-            specifier.start! + startOffset,
-            specifier.end! + startOffset,
-            `defineAsyncComponent as ${local}`,
-          )
-        }
-
         const existing = ctx.userImports[local]
         if (source === 'vue' && MACROS.includes(imported)) {
           if (local === imported) {

+ 2 - 1
packages/vue/src/index-with-vapor.ts

@@ -2,4 +2,5 @@
 export * from './index'
 export * from '@vue/runtime-vapor'
 export type { VaporSlot } from '@vue/runtime-vapor'
-export { withAsyncContext } from '@vue/runtime-vapor'
+// Override the standard runtime alias so Vapor builds keep the Vapor wrapper.
+export { defineVaporAsyncComponent, withAsyncContext } from '@vue/runtime-vapor'

+ 3 - 0
packages/vue/src/index.ts

@@ -105,3 +105,6 @@ registerRuntimeCompiler(compileToFunction)
 
 export { compileToFunction as compile }
 export * from '@vue/runtime-dom'
+// SSR uses the standard runtime entry, so expose the Vapor async name as the
+// VDOM async wrapper for hand-written imports outside SFC compileScript.
+export { defineAsyncComponent as defineVaporAsyncComponent } from '@vue/runtime-dom'

+ 2 - 1
packages/vue/src/runtime-with-vapor.ts

@@ -1,4 +1,5 @@
 export * from './runtime'
 export * from '@vue/runtime-vapor'
 export type { VaporSlot } from '@vue/runtime-vapor'
-export { withAsyncContext } from '@vue/runtime-vapor'
+// Override the standard runtime alias so Vapor builds keep the Vapor wrapper.
+export { defineVaporAsyncComponent, withAsyncContext } from '@vue/runtime-vapor'

+ 3 - 0
packages/vue/src/runtime.ts

@@ -9,6 +9,9 @@ if (__DEV__) {
 }
 
 export * from '@vue/runtime-dom'
+// SSR uses the standard runtime entry, so expose the Vapor async name as the
+// VDOM async wrapper for hand-written imports outside SFC compileScript.
+export { defineAsyncComponent as defineVaporAsyncComponent } from '@vue/runtime-dom'
 
 export const compile = (_template: string): RenderFunction => {
   if (__DEV__) {