Skip to content

Commit

Permalink
feat: support option rootId to empty root
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkXia committed Dec 5, 2024
1 parent 6b3167a commit b20846b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/plugin-stream-error/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# @ice/plugin-stream-error

## 1.0.3

- feat: empty root element when stream error

## 1.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-stream-error/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/plugin-stream-error",
"version": "1.0.2",
"version": "1.0.3",
"description": "",
"license": "MIT",
"type": "module",
Expand Down
12 changes: 10 additions & 2 deletions packages/plugin-stream-error/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import type { Plugin } from '@ice/app/types';

interface PluginOptions {
activeInDev?: boolean;
rootId?: string;
}

const PLUGIN_NAME = '@ice/plugin-stream-error';
const plugin: Plugin<PluginOptions> = (options = {}) => ({
const plugin: Plugin<PluginOptions> = (options = {
rootId: 'root',
}) => ({
name: PLUGIN_NAME,
setup: ({ generator, context }) => {
const { activeInDev } = options;
const { activeInDev, rootId } = options;
const { userConfig } = context;
if (userConfig.ssr) {
generator.addEntryCode((originalCode) => {
Expand All @@ -18,6 +21,11 @@ if (import.meta.renderer === 'client') {
// _$ServerTimePoints will returned at the end of last stream,
// if the value is undefined, try to re-render app with CSR.
if (${activeInDev ? '' : 'process.env.NODE_ENV === \'production\' && '}!window._$ServerTimePoints && window.__ICE_APP_CONTEXT__.renderMode === 'SSR') {
const root = document.getElementById('${rootId}');
if (root) {
root.innerHTML = '';
}
window.__ICE_APP_CONTEXT__.renderMode = 'CSR';
render({ hydrate: false });
}
});
Expand Down

0 comments on commit b20846b

Please sign in to comment.