feat: support custom props when render document (#7099)
CI / build (16.x, ubuntu-latest) (push) Waiting to run Details
CI / build (16.x, windows-latest) (push) Waiting to run Details
CI / build (18.x, ubuntu-latest) (push) Waiting to run Details
CI / build (18.x, windows-latest) (push) Waiting to run Details
Coverage / coverage (16.x) (push) Waiting to run Details
Release / Release (16) (push) Waiting to run Details

* feat: support custom props when render document

* Update packages/runtime/src/types.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update packages/runtime/src/renderDocument.tsx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix: test case

* Update runServerApp.tsx

* fix: optimize props

* chore: optimize code

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
ClarkXia 2025-06-30 11:17:22 +08:00 committed by GitHub
parent 80250ffe6e
commit cc0792b0fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 19 additions and 5 deletions

View File

@ -0,0 +1,5 @@
---
'@ice/runtime': patch
---
feat: support custom props when render document

View File

@ -0,0 +1,5 @@
---
'@ice/app': patch
---
fix: minify server bundle when build in prod

View File

@ -184,6 +184,7 @@ export function createServerCompiler(options: Options) {
// while it is not recommended // while it is not recommended
loader: { '.js': 'jsx' }, loader: { '.js': 'jsx' },
jsx: 'automatic', jsx: 'automatic',
minify: !dev,
sourcemap: typeof sourceMap === 'boolean' sourcemap: typeof sourceMap === 'boolean'
// Transform sourceMap for esbuild. // Transform sourceMap for esbuild.
? sourceMap : (sourceMap.includes('inline') ? 'inline' : !!sourceMap), ? sourceMap : (sourceMap.includes('inline') ? 'inline' : !!sourceMap),

View File

@ -59,6 +59,7 @@ interface RenderOptions {
publicPath?: string; publicPath?: string;
serverData?: any; serverData?: any;
streamOptions?: RenderToPipeableStreamOptions; streamOptions?: RenderToPipeableStreamOptions;
documentProps?: Record<string, unknown>;
} }
export async function renderToHTML(requestContext, options: RenderOptions = {}) { export async function renderToHTML(requestContext, options: RenderOptions = {}) {

View File

@ -45,6 +45,7 @@ export function renderDocument(options: RenderDocumentOptions): Response {
basename, basename,
routesConfig = {}, routesConfig = {},
serverData, serverData,
documentProps,
} = renderOptions; } = renderOptions;
const appData = null; const appData = null;
@ -84,7 +85,7 @@ export function renderDocument(options: RenderDocumentOptions): Response {
<AppContextProvider value={appContext}> <AppContextProvider value={appContext}>
<DocumentContextProvider value={documentContext}> <DocumentContextProvider value={documentContext}>
{ {
Document && <Document pagePath={routePath} /> Document && <Document pagePath={routePath} {...documentProps} />
} }
</DocumentContextProvider> </DocumentContextProvider>
</AppContextProvider>, </AppContextProvider>,

View File

@ -283,7 +283,7 @@ async function renderServerEntry(
renderOptions, renderOptions,
}: RenderServerEntry, }: RenderServerEntry,
): Promise<Response> { ): Promise<Response> {
const { Document } = renderOptions; const { Document, documentProps } = renderOptions;
const appContext = runtime.getAppContext(); const appContext = runtime.getAppContext();
const { routes, routePath, loaderData, basename } = appContext; const { routes, routePath, loaderData, basename } = appContext;
const AppRuntimeProvider = runtime.composeAppProvider() || React.Fragment; const AppRuntimeProvider = runtime.composeAppProvider() || React.Fragment;
@ -307,7 +307,7 @@ async function renderServerEntry(
<AppRuntimeProvider> <AppRuntimeProvider>
<DocumentContextProvider value={documentContext}> <DocumentContextProvider value={documentContext}>
{ {
Document && <Document pagePath={routePath} /> Document && <Document pagePath={routePath} {...documentProps} />
} }
</DocumentContextProvider> </DocumentContextProvider>
</AppRuntimeProvider> </AppRuntimeProvider>

View File

@ -338,6 +338,7 @@ export interface RenderOptions {
runtimeOptions?: Record<string, any>; runtimeOptions?: Record<string, any>;
serverData?: any; serverData?: any;
streamOptions?: RenderToPipeableStreamOptions; streamOptions?: RenderToPipeableStreamOptions;
documentProps?: Record<string, unknown>;
} }
declare global { declare global {

View File

@ -20,7 +20,7 @@ describe(`build ${example}`, () => {
sizeFallback = fs.statSync(fallbackPath).size; sizeFallback = fs.statSync(fallbackPath).size;
expect(sizeFallback).toBeLessThan(sizeServer); expect(sizeFallback).toBeLessThan(sizeServer);
// The Stat size of fallback entry will reduce more than 50kb. // The Stat size of fallback entry will reduce more than 50kb, minify size is 20kb.
expect(sizeServer - sizeFallback).toBeGreaterThan(50 * 1024); expect(sizeServer - sizeFallback).toBeGreaterThan(20 * 1024);
}); });
}); });