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

chore(rsc): Fix TODO and simplify SSR code #11650

Merged
merged 1 commit into from
Oct 4, 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
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
Loading