/
githubmr
/
facebook-react
Обзор
Документация
Войти
/
githubmr
/
facebook-react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
fixtures/flight-esm/src/index.js
57 строк
1 KB
Sebastian Markbåge
[Flight ESM] Wire up Source Maps in the flight-esm fixture (#30758)
22 авг 2024, 19:34
Не верифицирован
22 авг 2024, 19:34
e483df4
Код
Авторство
О чём код?
import * as React from 'react'; import {use, Suspense, useState, startTransition} from 'react'; import ReactDOM from 'react-dom/client'; import {createFromFetch, encodeReply} from 'react-server-dom-esm/client'; const moduleBaseURL = '/src/'; function findSourceMapURL(fileName) { return ( document.location.origin + '/source-maps?name=' + encodeURIComponent(fileName) ); } let updateRoot; async function callServer(id, args) { const response = fetch('/', { method: 'POST', headers: { Accept: 'text/x-component', 'rsc-action': id, }, body: await encodeReply(args), }); const {returnValue, root} = await createFromFetch(response, { callServer, moduleBaseURL, findSourceMapURL, }); // Refresh the tree with the new RSC payload. startTransition(() => { updateRoot(root); }); return returnValue; } let data = createFromFetch( fetch('/', { headers: { Accept: 'text/x-component', }, }), { callServer, moduleBaseURL, findSourceMapURL, } ); function Shell({data}) { const [root, setRoot] = useState(use(data)); updateRoot = setRoot; return root; } ReactDOM.hydrateRoot(document, React.createElement(Shell, {data}));