Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
try bundling react-server-dom-webpack/server
Browse files Browse the repository at this point in the history
jtoar committed Mar 16, 2024
1 parent a5ef8c0 commit 6ab737a
Showing 5 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/vite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
compiled
17 changes: 17 additions & 0 deletions packages/vite/build.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
import { build } from '@redwoodjs/framework-tools'

import * as esbuild from 'esbuild'

await build()

// Bundle react dependencies without poisoned imports
// so that we don't need the react-server condition at runtime.

await esbuild.build({
entryPoints: ['prebundled/react-server-dom-webpack.server.js'],
outdir: 'compiled',

bundle: true,
conditions: ['react-server'],
platform: 'node',
target: ['node20'],

logLevel: 'info',
})
3 changes: 2 additions & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
@@ -54,7 +54,8 @@
"files": [
"dist",
"inject",
"cjsWrapper.js"
"cjsWrapper.js",
"compiled"
],
"scripts": {
"build": "tsx build.mts && yarn build:types",
4 changes: 4 additions & 0 deletions packages/vite/prebundled/react-server-dom-webpack.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export {
decodeReply,
decodeReplyFromBusboy,
} from 'react-server-dom-webpack/server'
8 changes: 5 additions & 3 deletions packages/vite/src/rsc/rscRequestHandler.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import busboy from 'busboy'
import type { Request, Response } from 'express'
import RSDWServer from 'react-server-dom-webpack/server.node.unbundled'

import {
decodeReply,
decodeReplyFromBusboy,
// @ts-expect-error todo
} from '../../compiled/react-server-dom-webpack.server'
import { hasStatusCode } from '../lib/StatusError.js'

import { sendRscFlightToStudio } from './rscStudioHandlers.js'
import { renderRsc } from './rscWorkerCommunication.js'

const { decodeReply, decodeReplyFromBusboy } = RSDWServer

export function createRscRequestHandler() {
// This is mounted at /rw-rsc, so will have /rw-rsc stripped from req.url
return async (req: Request, res: Response, next: () => void) => {

0 comments on commit 6ab737a

Please sign in to comment.