Skip to content

Commit

Permalink
fix: tree shaking rsc code
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjun1011 committed Dec 7, 2023
1 parent 1f67237 commit f313534
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions packages/ice/templates/core/entry.server.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import './env.server';
import {
getAppConfig,
renderToHTML as originRenderToHTML,
renderToResponse as originRenderToResponse,
renderToEntry as originRenderToEntry } from '@ice/runtime/server';
import * as runtime from '@ice/runtime/server';
<% if (hydrate) {-%>
import { commons, statics } from './runtime-modules';
<% }-%>
Expand All @@ -18,7 +14,7 @@ import type { RenderToPipeableStreamOptions } from 'react-dom/server';
// @ts-ignore
import assetsManifest from 'virtual:assets-manifest.json';
<% if(rsc) {-%>
import { runRSCServerApp } from '@ice/runtime/server';
import { runRSCServerApp } from '@ice/runtime/rsc';
import clientManifest from 'virtual:react-client-manifest.json';
import serverManifest from 'virtual:react-ssr-manifest.json';
import rscModule from 'virtual-rsc-module:react-ssr-manifest.json';
Expand All @@ -40,7 +36,7 @@ const createRoutes = () => routesManifest;
const runtimeModules = { commons, statics };

const getRouterBasename = () => {
const appConfig = getAppConfig(app);
const appConfig = runtime.getAppConfig(app);
return appConfig?.router?.basename ?? <%- basename %> ?? '';
}

Expand Down Expand Up @@ -74,7 +70,7 @@ export async function renderToHTML(requestContext, options: RenderOptions = {})
setRuntimeEnv(renderMode);

const mergedOptions = mergeOptions(options);
return await originRenderToHTML(requestContext, mergedOptions);
return await runtime.renderToHTML(requestContext, mergedOptions);
}

export async function renderToResponse(requestContext, options: RenderOptions = {}) {
Expand All @@ -86,7 +82,7 @@ export async function renderToResponse(requestContext, options: RenderOptions =
<% if(rsc) {-%>
return runRSCServerApp(requestContext, mergedOptions);
<% } else { -%>
return originRenderToResponse(requestContext, mergedOptions);
return runtime.renderToResponse(requestContext, mergedOptions);
<% }-%>
}

Expand All @@ -96,7 +92,7 @@ export async function renderToEntry(requestContext, options: RenderOptions = {})
setRuntimeEnv(renderMode);
const mergedOptions = mergeOptions(options);
return await originRenderToEntry(requestContext, mergedOptions);
return await runtime.renderToEntry(requestContext, mergedOptions);
}
<% } -%>

Expand Down
1 change: 1 addition & 0 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
".": "./esm/index.js",
"./client": "./esm/index.js",
"./server": "./esm/index.server.js",
"./rsc": "./esm/runRSCServerApp.js",
"./jsx-runtime": "./esm/jsx-runtime.js",
"./jsx-dev-runtime": "./esm/jsx-dev-runtime.js",
"./matchRoutes": "./esm/matchRoutes.js",
Expand Down
1 change: 0 additions & 1 deletion packages/runtime/src/index.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { renderToResponse, renderToHTML, renderToEntry } from './runServerApp.js';
export { runRSCServerApp } from './runRSCServerApp.js';

export * from './index.js';

0 comments on commit f313534

Please sign in to comment.