(res, returnValue, formState, noCache)
| 134 | } |
| 135 | |
| 136 | async function prerenderApp(res, returnValue, formState, noCache) { |
| 137 | const {prerenderToNodeStream} = await import( |
| 138 | 'react-server-dom-unbundled/static' |
| 139 | ); |
| 140 | // const m = require('../src/App.js'); |
| 141 | const m = await import('../src/App.js'); |
| 142 | |
| 143 | let moduleMap; |
| 144 | let mainCSSChunks; |
| 145 | if (process.env.NODE_ENV === 'development') { |
| 146 | // Read the module map from the HMR server in development. |
| 147 | moduleMap = await ( |
| 148 | await fetch('http://localhost:3000/react-client-manifest.json') |
| 149 | ).json(); |
| 150 | mainCSSChunks = ( |
| 151 | await ( |
| 152 | await fetch('http://localhost:3000/entrypoint-manifest.json') |
| 153 | ).json() |
| 154 | ).main.css; |
| 155 | } else { |
| 156 | // Read the module map from the static build in production. |
| 157 | moduleMap = JSON.parse( |
| 158 | await readFile( |
| 159 | path.resolve(__dirname, `../build/react-client-manifest.json`), |
| 160 | 'utf8' |
| 161 | ) |
| 162 | ); |
| 163 | mainCSSChunks = JSON.parse( |
| 164 | await readFile( |
| 165 | path.resolve(__dirname, `../build/entrypoint-manifest.json`), |
| 166 | 'utf8' |
| 167 | ) |
| 168 | ).main.css; |
| 169 | } |
| 170 | const App = m.default.default || m.default; |
| 171 | const root = React.createElement( |
| 172 | React.Fragment, |
| 173 | null, |
| 174 | // Prepend the App's tree with stylesheets required for this entrypoint. |
| 175 | mainCSSChunks.map(filename => |
| 176 | React.createElement('link', { |
| 177 | rel: 'stylesheet', |
| 178 | href: filename, |
| 179 | precedence: 'default', |
| 180 | key: filename, |
| 181 | }) |
| 182 | ), |
| 183 | React.createElement(App, {prerender: true, noCache}) |
| 184 | ); |
| 185 | // For client-invoked server actions we refresh the tree and return a return value. |
| 186 | const payload = {root, returnValue, formState}; |
| 187 | const {prelude} = await prerenderToNodeStream(payload, moduleMap, { |
| 188 | filterStackFrame, |
| 189 | }); |
| 190 | prelude.pipe(res); |
| 191 | } |
| 192 | |
| 193 | app.get('/', async function (req, res) { |
no test coverage detected