mirror of https://github.com/alibaba/ice.git
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
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:
parent
80250ffe6e
commit
cc0792b0fd
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@ice/runtime': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: support custom props when render document
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@ice/app': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: minify server bundle when build in prod
|
|
@ -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),
|
||||||
|
|
|
@ -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 = {}) {
|
||||||
|
|
|
@ -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>,
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue