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

RSC: No need to use memo or useMemo in the server router #10568

Merged
merged 1 commit into from
May 13, 2024
Merged
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
24 changes: 10 additions & 14 deletions packages/router/src/server-router.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ReactNode } from 'react'
import React, { useMemo, memo } from 'react'
import React from 'react'

import { analyzeRoutes } from './analyzeRoutes'
import type { Wrappers } from './analyzeRoutes'
Expand All @@ -25,24 +25,20 @@ export const Router: React.FC<RouterProps> = ({
children,
location,
}) => {
const analyzeRoutesResult = useMemo(() => {
const analyzedRoutes = analyzeRoutes(children, {
currentPathName: location.pathname,
// @TODO We haven't handled this with SSR/Streaming yet.
// May need a babel plugin to extract userParamTypes from Routes.tsx
userParamTypes: paramTypes,
})

return analyzedRoutes
}, [location.pathname, children, paramTypes])
const analyzedRoutes = analyzeRoutes(children, {
currentPathName: location.pathname,
// @TODO We haven't handled this with SSR/Streaming yet.
// May need a babel plugin to extract userParamTypes from Routes.tsx
userParamTypes: paramTypes,
})

const {
pathRouteMap,
hasHomeRoute,
namedRoutesMap,
NotFoundPage,
activeRoutePath,
} = analyzeRoutesResult
} = analyzedRoutes

// Assign namedRoutes so it can be imported like import {routes} from 'rwjs/router'
// Note that the value changes at runtime
Expand Down Expand Up @@ -172,7 +168,7 @@ interface WrappedPageProps {
* This is so that we can have all the information up front in the routes-manifest
* for SSR, but also so that we only do one loop of all the Routes.
*/
const WrappedPage = memo(({ routeLoaderElement, sets }: WrappedPageProps) => {
const WrappedPage = ({ routeLoaderElement, sets }: WrappedPageProps) => {
// @NOTE: don't mutate the wrappers array, it causes full page re-renders
// Instead just create a new array with the AuthenticatedRoute wrapper

Expand Down Expand Up @@ -219,4 +215,4 @@ const WrappedPage = memo(({ routeLoaderElement, sets }: WrappedPageProps) => {

return wrapped
}, routeLoaderElement)
})
}
Loading