Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ssr): handle symboless Modules in dynamic imports #2355

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/router/__tests__/guards/loadRouteLocation.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
26 changes: 2 additions & 24 deletions packages/router/src/navigationGuards.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
isRouteLocation,
Lazy,
RouteComponent,
RawRouteComponent,
} from './types'
import { isRouteLocation, Lazy, RouteComponent } from './types'

import type {
RouteLocationNormalized,
Expand All @@ -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(
Expand Down Expand Up @@ -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>`.
*
Expand Down
26 changes: 25 additions & 1 deletion packages/router/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down