]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(ssr): handle symboless Modules in dynamic imports (#2355)
authorEduardo San Martin Morote <posva@users.noreply.github.com>
Tue, 10 Sep 2024 13:27:23 +0000 (15:27 +0200)
committerGitHub <noreply@github.com>
Tue, 10 Sep 2024 13:27:23 +0000 (15:27 +0200)
* fix(ssr): handle symboless Modules in dynamic imports

* chore: fix types

packages/router/__tests__/guards/loadRouteLocation.spec.ts
packages/router/src/navigationGuards.ts
packages/router/src/utils/index.ts

index e4d98612b9a02958f3b961570c8d1950f239f71a..af7f1cee888e316b7f73847668cbe3886bed3dd2 100644 (file)
@@ -1,9 +1,10 @@
-import { isRouteComponent, loadRouteLocation } from '../../src/navigationGuards'
+import { loadRouteLocation } from '../../src/navigationGuards'
 import { RouteRecordRaw } from '../../src/types'
 import { components } from '../utils'
 import { RouteLocationRaw, createMemoryHistory, createRouter } from '../../src'
 import { FunctionalComponent } from 'vue'
 import { describe, expect, it } from 'vitest'
+import { isRouteComponent } from '../../src/utils'
 
 const FunctionalHome: FunctionalComponent = () => null
 FunctionalHome.displayName = 'Home'
index b1b9268a5e5674802a198fd7c82c26829c0ba8be..3c421590b1f7b41642eaa4240b764f65db226979 100644 (file)
@@ -1,9 +1,4 @@
-import {
-  isRouteLocation,
-  Lazy,
-  RouteComponent,
-  RawRouteComponent,
-} from './types'
+import { isRouteLocation, Lazy, RouteComponent } from './types'
 
 import type {
   RouteLocationNormalized,
@@ -25,7 +20,7 @@ import { ComponentOptions, onUnmounted, onActivated, onDeactivated } from 'vue'
 import { inject, getCurrentInstance } from 'vue'
 import { matchedRouteKey } from './injectionSymbols'
 import { RouteRecordNormalized } from './matcher/types'
-import { isESModule } from './utils'
+import { isESModule, isRouteComponent } from './utils'
 import { warn } from './warning'
 
 function registerGuard(
@@ -349,23 +344,6 @@ export function extractComponentsGuards(
   return guards
 }
 
-/**
- * Allows differentiating lazy components from functional components and vue-class-component
- * @internal
- *
- * @param component
- */
-export function isRouteComponent(
-  component: RawRouteComponent
-): component is RouteComponent {
-  return (
-    typeof component === 'object' ||
-    'displayName' in component ||
-    'props' in component ||
-    '__vccOpts' in component
-  )
-}
-
 /**
  * Ensures a route is loaded, so it can be passed as o prop to `<RouterView>`.
  *
index cb5ac7bc4757a940b7150dfb4c2cd48e1a2854ec..b63f9dbb3d921e6704c1be8626a927ae23975732 100644 (file)
@@ -3,12 +3,36 @@ import {
   RouteComponent,
   RouteParamsRawGeneric,
   RouteParamValueRaw,
+  RawRouteComponent,
 } from '../types'
 
 export * from './env'
 
+/**
+ * Allows differentiating lazy components from functional components and vue-class-component
+ * @internal
+ *
+ * @param component
+ */
+export function isRouteComponent(
+  component: RawRouteComponent
+): component is RouteComponent {
+  return (
+    typeof component === 'object' ||
+    'displayName' in component ||
+    'props' in component ||
+    '__vccOpts' in component
+  )
+}
+
 export function isESModule(obj: any): obj is { default: RouteComponent } {
-  return obj.__esModule || obj[Symbol.toStringTag] === 'Module'
+  return (
+    obj.__esModule ||
+    obj[Symbol.toStringTag] === 'Module' ||
+    // support CF with dynamic imports that do not
+    // add the Module string tag
+    (obj.default && isRouteComponent(obj.default))
+  )
 }
 
 export const assign = Object.assign