client.tsx — react Source File
Architecture documentation for client.tsx, a tsx file in the react codebase. 4 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 92a57e25_d5ae_6cfd_c67c_ec168f4dede5["client.tsx"] ac587885_e294_a1e9_b13f_5e7b920fdb42["react"] 92a57e25_d5ae_6cfd_c67c_ec168f4dede5 --> ac587885_e294_a1e9_b13f_5e7b920fdb42 8792c1c1_dca5_f137_73ea_c0e268fdbb22["client"] 92a57e25_d5ae_6cfd_c67c_ec168f4dede5 --> 8792c1c1_dca5_f137_73ea_c0e268fdbb22 51ce1a9c_a088_8041_82ab_f57934e4991f["client"] 92a57e25_d5ae_6cfd_c67c_ec168f4dede5 --> 51ce1a9c_a088_8041_82ab_f57934e4991f f7d1dc33_c70d_91ec_f376_8a29f1bd606f["client"] 92a57e25_d5ae_6cfd_c67c_ec168f4dede5 --> f7d1dc33_c70d_91ec_f376_8a29f1bd606f c3489d06_1452_f7f8_d28f_240d296f1926["Todos.tsx"] c3489d06_1452_f7f8_d28f_240d296f1926 --> 92a57e25_d5ae_6cfd_c67c_ec168f4dede5 style 92a57e25_d5ae_6cfd_c67c_ec168f4dede5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
'use client-entry';
import {
useState,
use,
startTransition,
useInsertionEffect,
ReactElement,
} from 'react';
import ReactDOM from 'react-dom/client';
import {
createFromReadableStream,
createFromFetch,
encodeReply,
setServerCallback,
} from 'react-server-dom-parcel/client';
import {rscStream} from 'rsc-html-stream/client';
// Stream in initial RSC payload embedded in the HTML.
let initialRSCPayload = createFromReadableStream<ReactElement>(rscStream);
let updateRoot:
| ((root: ReactElement, cb?: (() => void) | null) => void)
| null = null;
function Content() {
// Store the current root element in state, along with a callback
// to call once rendering is complete.
let [[root, cb], setRoot] = useState<[ReactElement, (() => void) | null]>([
use(initialRSCPayload),
null,
]);
updateRoot = (root, cb) => setRoot([root, cb ?? null]);
useInsertionEffect(() => cb?.());
return root;
}
// Hydrate initial page content.
startTransition(() => {
ReactDOM.hydrateRoot(document, <Content />);
});
// A very simple router. When we navigate, we'll fetch a new RSC payload from the server,
// and in a React transition, stream in the new page. Once complete, we'll pushState to
// update the URL in the browser.
async function navigate(pathname: string, push = false) {
let res = fetch(pathname, {
headers: {
Accept: 'text/x-component',
},
});
let root = await createFromFetch<ReactElement>(res);
startTransition(() => {
updateRoot!(root, () => {
if (push) {
history.pushState(null, '', pathname);
push = false;
}
});
});
}
// Intercept link clicks to perform RSC navigation.
document.addEventListener('click', e => {
let link = (e.target as Element).closest('a');
if (
link &&
link instanceof HTMLAnchorElement &&
link.href &&
(!link.target || link.target === '_self') &&
link.origin === location.origin &&
!link.hasAttribute('download') &&
e.button === 0 && // left clicks only
!e.metaKey && // open in new tab (mac)
!e.ctrlKey && // open in new tab (windows)
!e.altKey && // download
!e.shiftKey &&
!e.defaultPrevented
) {
e.preventDefault();
navigate(link.pathname, true);
}
});
// When the user clicks the back button, navigate with RSC.
window.addEventListener('popstate', e => {
navigate(location.pathname);
});
// Intercept HMR window reloads, and do it with RSC instead.
window.addEventListener('parcelhmrreload', e => {
e.preventDefault();
navigate(location.pathname);
});
// Setup a callback to perform server actions.
// This sends a POST request to the server, and updates the page with the response.
setServerCallback(async function (id: string, args: any[]) {
console.log('Handling server action', id, args);
const response = fetch(location.pathname, {
method: 'POST',
headers: {
Accept: 'text/x-component',
'rsc-action-id': id,
},
body: await encodeReply(args),
});
const {result, root} = await createFromFetch<{
root: JSX.Element;
result: any;
}>(response);
startTransition(() => updateRoot!(root));
return result;
});
Domain
Subdomains
Functions
Dependencies
- client
- client
- client
- react
Imported By
Source
Frequently Asked Questions
What does client.tsx do?
client.tsx is a source file in the react codebase, written in tsx. It belongs to the BabelCompiler domain, Optimization subdomain.
What functions are defined in client.tsx?
client.tsx defines 3 function(s): Content, navigate, root.
What does client.tsx depend on?
client.tsx imports 4 module(s): client, client, client, react.
What files import client.tsx?
client.tsx is imported by 1 file(s): Todos.tsx.
Where is client.tsx in the architecture?
client.tsx is located at fixtures/flight-parcel/src/client.tsx (domain: BabelCompiler, subdomain: Optimization, directory: fixtures/flight-parcel/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free