| 76 | } |
| 77 | |
| 78 | async function renderApp(res, returnValue, formState, noCache, debugChannel) { |
| 79 | const {renderToPipeableStream} = await import( |
| 80 | 'react-server-dom-unbundled/server' |
| 81 | ); |
| 82 | // const m = require('../src/App.js'); |
| 83 | const m = await import('../src/App.js'); |
| 84 | |
| 85 | let moduleMap; |
| 86 | let mainCSSChunks; |
| 87 | if (process.env.NODE_ENV === 'development') { |
| 88 | // Read the module map from the HMR server in development. |
| 89 | moduleMap = await ( |
| 90 | await fetch('http://localhost:3000/react-client-manifest.json') |
| 91 | ).json(); |
| 92 | mainCSSChunks = ( |
| 93 | await ( |
| 94 | await fetch('http://localhost:3000/entrypoint-manifest.json') |
| 95 | ).json() |
| 96 | ).main.css; |
| 97 | } else { |
| 98 | // Read the module map from the static build in production. |
| 99 | moduleMap = JSON.parse( |
| 100 | await readFile( |
| 101 | path.resolve(__dirname, `../build/react-client-manifest.json`), |
| 102 | 'utf8' |
| 103 | ) |
| 104 | ); |
| 105 | mainCSSChunks = JSON.parse( |
| 106 | await readFile( |
| 107 | path.resolve(__dirname, `../build/entrypoint-manifest.json`), |
| 108 | 'utf8' |
| 109 | ) |
| 110 | ).main.css; |
| 111 | } |
| 112 | const App = m.default.default || m.default; |
| 113 | const root = React.createElement( |
| 114 | React.Fragment, |
| 115 | null, |
| 116 | // Prepend the App's tree with stylesheets required for this entrypoint. |
| 117 | mainCSSChunks.map(filename => |
| 118 | React.createElement('link', { |
| 119 | rel: 'stylesheet', |
| 120 | href: filename, |
| 121 | precedence: 'default', |
| 122 | key: filename, |
| 123 | }) |
| 124 | ), |
| 125 | React.createElement(App, {noCache}) |
| 126 | ); |
| 127 | // For client-invoked server actions we refresh the tree and return a return value. |
| 128 | const payload = {root, returnValue, formState}; |
| 129 | const {pipe} = renderToPipeableStream(payload, moduleMap, { |
| 130 | debugChannel, |
| 131 | filterStackFrame, |
| 132 | }); |
| 133 | pipe(res); |
| 134 | } |
| 135 | |