Skip to content
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
7 changes: 3 additions & 4 deletions packages/router/src/router.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { isValidElement } from 'react'

import { ActiveRouteLoader } from './active-route-loader'
import { useActivePageContext } from './ActivePageContext'
Expand All @@ -13,7 +13,6 @@ import {
import { SplashPage } from './splash-page'
import {
flattenAll,
isReactElement,
parseSearch,
replaceParams,
matchPath,
Expand Down Expand Up @@ -126,7 +125,7 @@ const InternalRoute = ({
function isRoute(
node: React.ReactNode
): node is React.ReactElement<InternalRouteProps> {
return isReactElement(node) && node.type === Route
return isValidElement(node) && node.type === Route
}

export interface RouterProps extends RouterContextProviderProps {
Expand Down Expand Up @@ -335,7 +334,7 @@ function analyzeRouterTree(

return childWithKey
}
} else if (isReactElement(child) && child.props.children) {
} else if (isValidElement(child) && child.props.children) {
// We have a child element that's not a <Route ...>, and that has
// children. It's probably a <Set>. Recurse down one level
const nestedActive = analyzeRouterTreeInternal(child.props.children)
Expand Down
12 changes: 2 additions & 10 deletions packages/router/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Children, ReactElement, ReactNode } from 'react'
import React, { Children, isValidElement, ReactNode } from 'react'

/** Create a React Context with the given name. */
export const createNamedContext = <T>(name: string, defaultValue?: T) => {
Expand Down Expand Up @@ -283,19 +283,11 @@ export const replaceParams = (
return path
}

export function isReactElement(node: ReactNode): node is ReactElement {
return (
node !== undefined &&
node !== null &&
(node as ReactElement).type !== undefined
)
}

export function flattenAll(children: ReactNode): ReactNode[] {
const childrenArray = Children.toArray(children)

return childrenArray.flatMap((child) => {
if (isReactElement(child) && child.props.children) {
if (isValidElement(child) && child.props.children) {
return [child, ...flattenAll(child.props.children)]
}

Expand Down