Skip to content

Commit

Permalink
Merge pull request #6277 from alibaba/release/next
Browse files Browse the repository at this point in the history
Release 3.2.3
  • Loading branch information
ClarkXia authored May 31, 2023
2 parents 87be462 + 45bb462 commit fa884ad
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 17 deletions.
12 changes: 12 additions & 0 deletions packages/ice/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 3.2.3

### Patch Changes

- 94e7dff2: fix: pass `getRoutesFile` for onDemand server runner.
- 51411c4e: feat: hooks for server render
- 71f32f9c: fix: add default polyfill for signal
- Updated dependencies [d1df9ffa]
- Updated dependencies [51411c4e]
- Updated dependencies [71f32f9c]
- @ice/runtime@1.2.2

## 3.2.2

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/ice/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/app",
"version": "3.2.2",
"version": "3.2.3",
"description": "provide scripts and configuration used by web framework ice",
"type": "module",
"main": "./esm/index.js",
Expand Down Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"@ice/bundles": "0.1.10",
"@ice/route-manifest": "1.2.0",
"@ice/runtime": "^1.2.1",
"@ice/runtime": "^1.2.2",
"@ice/webpack-config": "1.0.15",
"@swc/helpers": "0.5.1",
"@types/express": "^4.17.14",
Expand Down
5 changes: 5 additions & 0 deletions packages/ice/src/createService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
RUNTIME_EXPORTS.forEach(exports => {
generatorAPI.addExport(exports);
});
// Add polyfills.
generatorAPI.addEntryImportAhead({
source: '@ice/runtime/polyfills/signal',
});
const routeManifest = new RouteManifest();
const ctx = new Context<Config, ExtendsPluginAPI>({
rootDir,
Expand Down Expand Up @@ -311,6 +315,7 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
task: platformTaskConfig,
server,
csr,
getRoutesFile: () => routeManifest.getRoutesFile(),
});
addWatchEvent([
/src\/?[\w*-:.$]+$/,
Expand Down
3 changes: 3 additions & 0 deletions packages/ice/src/service/ServerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface InitOptions {
server: UserConfig['server'];
csr: boolean;
task: TaskConfig<Config>;
getRoutesFile: () => string[];
}

type ResolveCallback = Parameters<PluginBuild['onResolve']>[1];
Expand Down Expand Up @@ -88,12 +89,14 @@ class ServerRunner extends Runner {
server,
rootDir,
csr,
getRoutesFile,
}: InitOptions) {
const transformPlugins = getCompilerPlugins(rootDir, {
...task.config,
fastRefresh: false,
enableEnv: false,
polyfill: false,
getRoutesFile,
swcOptions: {
nodeTransform: true,
// Remove all exports except pageConfig when ssr and ssg both are false.
Expand Down
12 changes: 4 additions & 8 deletions packages/ice/templates/core/entry.server.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { commons, statics } from './runtimeModules';
import * as app from '@/app';
import Document from '@/document';
import type { RenderMode, DistType } from '@ice/runtime';
import type { RenderToPipeableStreamOptions } from 'react-dom/server';
// @ts-ignore
import assetsManifest from 'virtual:assets-manifest.json';
import createRoutes from './routes';
Expand Down Expand Up @@ -42,6 +43,7 @@ interface RenderOptions {
distType?: DistType;
publicPath?: string;
serverData?: any;
streamOptions?: RenderToPipeableStreamOptions;
}

export async function renderToHTML(requestContext, options: RenderOptions = {}) {
Expand Down Expand Up @@ -71,28 +73,22 @@ export async function renderToEntry(requestContext, options: RenderOptions = {})
<% } -%>

function mergeOptions(options) {
const { documentOnly, renderMode = 'SSR', basename, serverOnlyBasename, routePath, disableFallback, distType, prependCode, serverData, publicPath } = options;
const { renderMode = 'SSR', basename, publicPath } = options;

if (publicPath) {
assetsManifest.publicPath = publicPath;
}

return {
...options,
app,
assetsManifest,
createRoutes,
runtimeModules,
Document,
serverOnlyBasename,
basename: basename || getRouterBasename(),
documentOnly,
renderMode,
routePath,
disableFallback,
routesConfig,
distType,
prependCode,
serverData,
runtimeOptions: {
<% if (runtimeOptions.exports) { -%>
<%- runtimeOptions.exports %>
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"webpack-dev-server": "^4.13.2"
},
"peerDependencies": {
"@ice/app": "^3.2.2",
"@ice/runtime": "^1.2.1"
"@ice/app": "^3.2.3",
"@ice/runtime": "^1.2.2"
},
"publishConfig": {
"access": "public"
Expand Down
8 changes: 8 additions & 0 deletions packages/runtime/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @ice/runtime

## 1.2.2

### Patch Changes

- d1df9ffa: fix: should return after reject error
- 51411c4e: feat: hooks for server render
- 71f32f9c: fix: add default polyfill for signal

## 1.2.1

### Patch Changes
Expand Down
9 changes: 6 additions & 3 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/runtime",
"version": "1.2.1",
"version": "1.2.2",
"description": "Runtime module for ice.js",
"type": "module",
"types": "./esm/index.d.ts",
Expand All @@ -15,7 +15,8 @@
"./router": "./esm/router.js",
"./single-router": "./esm/singleRouter.js",
"./types": "./esm/types.js",
"./package.json": "./package.json"
"./package.json": "./package.json",
"./polyfills/signal": "./esm/polyfills/signal.js"
},
"files": [
"esm",
Expand All @@ -42,7 +43,9 @@
"regenerator-runtime": "^0.13.9",
"@remix-run/web-fetch": "^4.3.3"
},
"sideEffects": false,
"sideEffects": [
"./esm/polyfills/signal.js"
],
"dependencies": {
"@ice/jsx-runtime": "^0.2.1",
"@remix-run/router": "1.6.1",
Expand Down
23 changes: 23 additions & 0 deletions packages/runtime/src/polyfills/signal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Add polyfill of Request.prototype.signal for some browser compatibility.
// eslint-disable-next-line
if (import.meta.renderer === 'client' && window.Request && !window.Request.prototype.hasOwnProperty('signal')) {
(function (self) {
const OriginalRequest = window.Request;
function Request(input: RequestInfo | URL, init?: RequestInit) {
if (input instanceof OriginalRequest) {
this.signal = input.signal;
}
this.signal = init.signal || this.signal || (function () {
if ('AbortController' in window) {
let ctrl = new AbortController();
return ctrl.signal;
}
}());
OriginalRequest.call(this, input, init);
}
Request.prototype = Object.create(OriginalRequest.prototype);
Request.prototype.constructor = Request;
// @ts-expect-error for overwrite the original Request.
self.Request = Request;
})(window);
}
13 changes: 13 additions & 0 deletions packages/runtime/src/runServerApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from 'react';
import * as ReactDOMServer from 'react-dom/server';
import { parsePath } from 'history';
import type { Location } from 'history';
import type { RenderToPipeableStreamOptions } from 'react-dom/server';
import type {
AppContext, RouteItem, ServerContext,
AppExport, AssetsManifest,
Expand Down Expand Up @@ -51,6 +52,7 @@ interface RenderOptions {
distType?: Array<'html' | 'javascript'>;
prependCode?: string;
serverData?: any;
streamOptions?: RenderToPipeableStreamOptions;
}

interface Piper {
Expand Down Expand Up @@ -154,12 +156,21 @@ export async function renderToResponse(requestContext: ServerContext, renderOpti
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html; charset=utf-8');

const { streamOptions = {} } = renderOptions;
const { onShellReady, onShellError, onError, onAllReady } = streamOptions;

return new Promise<void>((resolve, reject) => {
// Send stream result to ServerResponse.
pipe(res, {
onShellReady: () => {
onShellReady && onShellReady();
},
onShellError: async (err) => {
onShellError && onShellError(err);

if (renderOptions.disableFallback) {
reject(err);
return;
}

// downgrade to CSR.
Expand All @@ -170,12 +181,14 @@ export async function renderToResponse(requestContext: ServerContext, renderOpti
resolve();
},
onError: async (err) => {
onError && onError(err);
// onError triggered after shell ready, should not downgrade to csr
// and should not be throw to break the render process
console.error('PipeToResponse error.');
console.error(err);
},
onAllReady: () => {
onAllReady && onAllReady();
resolve();
},
});
Expand Down
23 changes: 21 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fa884ad

Please sign in to comment.