Skip to content

Commit

Permalink
chore(rsc): Fix TODO and simplify SSR code (#11650)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Oct 4, 2024
1 parent 4a7b887 commit 1939f55
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions packages/router/src/rsc/clientSsr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { default as RSDWServerModule } from 'react-server-dom-webpack/serve

import { getPaths } from '@redwoodjs/project-config'

import { getRscStylesheetLinkGenerator } from './rscCss.js'
import { moduleMap } from './ssrModuleMap.js'
import { importRsdwClient, importReact } from './utils.js'
import { makeFilePath } from './utils.js'
Expand All @@ -19,9 +18,7 @@ async function getEntries() {
return entries
}

async function getRoutesComponent<TProps>(): Promise<
React.FunctionComponent<TProps>
> {
async function getRoutesComponent(): Promise<React.FunctionComponent> {
const { serverEntries } = await getEntries()
const entryPath = path.join(
getPaths().web.distRsc,
Expand Down Expand Up @@ -77,18 +74,15 @@ function resolveClientEntryForProd(

const rscCache = new Map<string, Thenable<React.ReactElement>>()

export async function renderRoutesSsr<TProps extends Record<string, any>>(
pathname: string,
) {
export async function renderRoutesSsr(pathname: string) {
console.log('renderRoutesSsr pathname', pathname)

const cached = rscCache.get(pathname)
if (cached) {
return cached
}

const cssLinks = getRscStylesheetLinkGenerator()()
const Routes = await getRoutesComponent<TProps>()
const Routes = await getRoutesComponent()

console.log('clientSsr.ts getEntries()', await getEntries())
const clientEntries = (await getEntries()).ssrEntries
Expand Down Expand Up @@ -131,18 +125,7 @@ export async function renderRoutesSsr<TProps extends Record<string, any>>(
// We're in clientSsr.ts, but we're supposed to be pretending we're in the
// RSC server "world" and that `stream` comes from `fetch`. So this is us
// emulating the reply (stream) you'd get from a fetch call.
const stream = renderToReadableStream(
// createElement(layout, undefined, createElement(page, props)),
createElement(Routes, {
// TODO (RSC): Include a more complete location object here. At least
// search params as well
// TODO (RSC): Get rid of this when the router can just use
// useLocation()
location: { pathname },
css: cssLinks,
}),
bundlerConfig,
)
const stream = renderToReadableStream(createElement(Routes), bundlerConfig)

// We have to do this weird import thing because we need a version of
// react-server-dom-webpack/client.edge that uses the same bundled version
Expand Down

0 comments on commit 1939f55

Please sign in to comment.