Skip to content
Open
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
7 changes: 6 additions & 1 deletion packages/plugin-rsc/src/react/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// @ts-ignore
import * as ReactClient from '@vitejs/plugin-rsc/vendor/react-server-dom/client.edge'
import { createServerConsumerManifest } from '../core/ssr'
import type { CreateFromReadableStreamEdgeOptions } from '../types'
import type {
CreateFromReadableStreamEdgeOptions,
EncodeReplyFunction,
} from '../types'

export { setRequireModule } from '../core/ssr'

Expand All @@ -19,5 +22,7 @@ export function createServerReference(id: string): unknown {
return ReactClient.createServerReference(id)
}

export const encodeReply: EncodeReplyFunction = ReactClient.encodeReply

export const callServer = null
export const findSourceMapURL = null
18 changes: 18 additions & 0 deletions packages/plugin-rsc/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface RenderToReadableStreamOptions {
export interface CreateFromReadableStreamBrowserOptions {
callServer?: CallServerCallback
debugChannel?: DebugChannel
encodeFormAction?: EncodeFormActionCallback
endTime?: number
environmentName?: string
replayConsoleLogs?: boolean
Expand All @@ -58,6 +59,7 @@ export interface CreateFromReadableStreamBrowserOptions {
// https://github.com/facebook/react/blob/8b2e903a7447d370eb77bb117bc4c0ae240ce831/packages/react-server-dom-webpack/src/client/ReactFlightDOMClientEdge.js#L74-L87
export interface CreateFromReadableStreamEdgeOptions {
debugChannel?: DebugChannel
encodeFormAction?: EncodeFormActionCallback
endTime?: number
environmentName?: string
nonce?: string
Expand All @@ -78,6 +80,22 @@ export interface EncodeReplyOptions {
signal?: AbortSignal
}

// https://github.com/facebook/react/blob/8b2e903a7447d370eb77bb117bc4c0ae240ce831/packages/react-client/src/ReactFlightReplyClient.js#L59-L62
export type EncodeFormActionCallback = (
id: string,
args: Promise<unknown[]>,
) => ReactCustomFormAction

// https://github.com/facebook/react/blob/8b2e903a7447d370eb77bb117bc4c0ae240ce831/packages/shared/ReactTypes.js#L153-L160
export type ReactCustomFormAction = {
name?: string
action?: string
encType?: string
method?: string
target?: string
data?: FormData | null
}

// TODO: technically encode/decodeReply can serialize non-array values
export type EncodeReplyFunction = (
value: unknown[],
Expand Down