Skip to content

Commit 4861467

Browse files
authored
fix(ssr): handle symboless Modules in dynamic imports (vuejs#2355)
* fix(ssr): handle symboless Modules in dynamic imports * chore: fix types
1 parent ba3ab9a commit 4861467

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

packages/router/__tests__/guards/loadRouteLocation.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { isRouteComponent, loadRouteLocation } from '../../src/navigationGuards'
1+
import { loadRouteLocation } from '../../src/navigationGuards'
22
import { RouteRecordRaw } from '../../src/types'
33
import { components } from '../utils'
44
import { RouteLocationRaw, createMemoryHistory, createRouter } from '../../src'
55
import { FunctionalComponent } from 'vue'
66
import { describe, expect, it } from 'vitest'
7+
import { isRouteComponent } from '../../src/utils'
78

89
const FunctionalHome: FunctionalComponent = () => null
910
FunctionalHome.displayName = 'Home'

packages/router/src/navigationGuards.ts

+2-24
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
isRouteLocation,
3-
Lazy,
4-
RouteComponent,
5-
RawRouteComponent,
6-
} from './types'
1+
import { isRouteLocation, Lazy, RouteComponent } from './types'
72

83
import type {
94
RouteLocationNormalized,
@@ -25,7 +20,7 @@ import { ComponentOptions, onUnmounted, onActivated, onDeactivated } from 'vue'
2520
import { inject, getCurrentInstance } from 'vue'
2621
import { matchedRouteKey } from './injectionSymbols'
2722
import { RouteRecordNormalized } from './matcher/types'
28-
import { isESModule } from './utils'
23+
import { isESModule, isRouteComponent } from './utils'
2924
import { warn } from './warning'
3025

3126
function registerGuard(
@@ -349,23 +344,6 @@ export function extractComponentsGuards(
349344
return guards
350345
}
351346

352-
/**
353-
* Allows differentiating lazy components from functional components and vue-class-component
354-
* @internal
355-
*
356-
* @param component
357-
*/
358-
export function isRouteComponent(
359-
component: RawRouteComponent
360-
): component is RouteComponent {
361-
return (
362-
typeof component === 'object' ||
363-
'displayName' in component ||
364-
'props' in component ||
365-
'__vccOpts' in component
366-
)
367-
}
368-
369347
/**
370348
* Ensures a route is loaded, so it can be passed as o prop to `<RouterView>`.
371349
*

packages/router/src/utils/index.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,36 @@ import {
33
RouteComponent,
44
RouteParamsRawGeneric,
55
RouteParamValueRaw,
6+
RawRouteComponent,
67
} from '../types'
78

89
export * from './env'
910

11+
/**
12+
* Allows differentiating lazy components from functional components and vue-class-component
13+
* @internal
14+
*
15+
* @param component
16+
*/
17+
export function isRouteComponent(
18+
component: RawRouteComponent
19+
): component is RouteComponent {
20+
return (
21+
typeof component === 'object' ||
22+
'displayName' in component ||
23+
'props' in component ||
24+
'__vccOpts' in component
25+
)
26+
}
27+
1028
export function isESModule(obj: any): obj is { default: RouteComponent } {
11-
return obj.__esModule || obj[Symbol.toStringTag] === 'Module'
29+
return (
30+
obj.__esModule ||
31+
obj[Symbol.toStringTag] === 'Module' ||
32+
// support CF with dynamic imports that do not
33+
// add the Module string tag
34+
(obj.default && isRouteComponent(obj.default))
35+
)
1236
}
1337

1438
export const assign = Object.assign

0 commit comments

Comments
 (0)