Skip to content

Commit

Permalink
RSC: No need to use memo or useMemo in the server router (redwoodjs#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed May 13, 2024
1 parent 34d1da9 commit 9dcaf31
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions packages/router/src/server-router.tsx
@@ -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)
})
}

0 comments on commit 9dcaf31

Please sign in to comment.