Skip to content
Source
Sign inSign up
TanStack/store
Open History to see the last commit

rsc-loader.mjs

18 lines711 Bytes

1import { load as loadRsc } from 'react-server-dom-webpack/node-loader'
2​
3export { resolve } from 'react-server-dom-webpack/node-loader'
4​
5/** @type {import('node:module').LoadHook} */
6export async function load(url, context, nextLoad) {
7 return loadRsc(url, context, async (specifier, nextContext) => {
8 // React also loads relative source-map URLs through this callback.
9 const result = await nextLoad(new URL(specifier, url).href, nextContext)
10​
11 // React's loader accepts text; Node's default loader can return bytes.
12 if (result.format === 'module' && typeof result.source !== 'string') {
13 return { ...result, source: new TextDecoder().decode(result.source) }
14 }
15​
16 return result
17 })