Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/docs/src/pages/api/Defer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ By default, FUNSTACK Static puts the entire app (`<App />`) into one RSC payload

When you use `defer(<Component />)`, FUNSTACK Static creates **additional RSC payloads** for the rendering result of the element. This results in an additional emit of RSC payload files like `/funstack__/fun:rsc-payload/b5698be72eea3c37`. If you provide a `name` option, the file name will include it (e.g., `/funstack__/fun:rsc-payload/HomePage-b5698be72eea3c37`).

In the main RSC payload, the `defer` call is replaced with a client component `<ClientWrapper moduleId="fun:rsc-payload/b5698be72eea3c37" />`. This component is responsible for fetching the additional RSC payload from client and renders it when it's ready.
In the main RSC payload, the `defer` call is replaced with a client component `<DeferredComponent moduleId="fun:rsc-payload/b5698be72eea3c37" />`. This component is responsible for fetching the additional RSC payload from client and renders it when it's ready.
6 changes: 4 additions & 2 deletions packages/static/src/rsc-client/clientWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ export const RegistryContext = createContext<DeferRegistry | undefined>(
undefined,
);

interface ClientWrapperProps {
interface DeferredComponentProps {
moduleID: string;
}

export const ClientWrapper: React.FC<ClientWrapperProps> = ({ moduleID }) => {
export const DeferredComponent: React.FC<DeferredComponentProps> = ({
moduleID,
}) => {
const registry = use(RegistryContext);
const modulePath = getModulePathFor(moduleID);
if (registry) {
Expand Down
2 changes: 1 addition & 1 deletion packages/static/src/rsc-client/entry.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"use client";

export { RegistryContext, ClientWrapper } from "./clientWrapper";
export { RegistryContext, DeferredComponent } from "./clientWrapper";
4 changes: 2 additions & 2 deletions packages/static/src/rsc/defer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ReactElement, ReactNode } from "react";
import { renderToReadableStream } from "@vitejs/plugin-rsc/react/rsc";
import { ClientWrapper } from "#rsc-client";
import { DeferredComponent } from "#rsc-client";
import { drainStream } from "../util/drainStream";
import { getPayloadIDFor } from "./rscModule";

Expand Down Expand Up @@ -206,5 +206,5 @@ export function defer(
const id = getPayloadIDFor(rawId);
deferRegistry.register(element, id, name);

return <ClientWrapper moduleID={id} />;
return <DeferredComponent moduleID={id} />;
}