Skip to content

Commit

Permalink
fix: dom crash with ssr hydrate error (ant-design#49576)
Browse files Browse the repository at this point in the history
* fix: ssr hydrate error

* deps: lock react and react-dom

* chore: script react/react-dom --nosave

* chore(deps): update dumi version

* chore: back ant-design#49595

* chore(deps): update dumi
  • Loading branch information
Jinbao1001 authored Jun 28, 2024
1 parent 3e98f7c commit 3952fd8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 48 deletions.
44 changes: 0 additions & 44 deletions .dumi/theme/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,6 @@ const RoutesPlugin = (api: IApi) => {
// exclude dynamic route path, to avoid deploy failed by `:id` directory
.filter((f) => !f.path.includes(':'))
.map((file) => {
let globalStyles = '';

// Debug for file content: uncomment this if need check raw out
// const tmpFileName = `_${file.path.replace(/\//g, '-')}`;
// const tmpFilePath = path.join(api.paths.absOutputPath, tmpFileName);
// fs.writeFileSync(tmpFilePath, file.content, 'utf8');

// extract all emotion style tags from body
file.content = file.content.replace(
/<style (data-emotion|data-sandpack)[\S\s]+?<\/style>/g,
(s) => {
globalStyles += s;

return '';
},
);

// insert emotion style tags to head
file.content = file.content.replace('</head>', `${globalStyles}</head>`);

// 1. 提取 antd-style 样式
const styles = extractEmotionStyle(file.content);

Expand All @@ -217,30 +197,6 @@ const RoutesPlugin = (api: IApi) => {
file.content = addLinkStyle(file.content, cssFile);
});

// Insert antd style to head
const matchRegex = /<style data-type="antd-cssinjs">([\S\s]+?)<\/style>/;
const matchList = file.content.match(matchRegex) || [];

// Init to order the `@layer`
let antdStyle = '@layer global, antd;';

matchList.forEach((text) => {
file.content = file.content.replace(text, '');
antdStyle += text.replace(matchRegex, '$1');
});

const cssFile = writeCSSFile('antd', antdStyle, antdStyle);
file.content = addLinkStyle(file.content, cssFile, true);

// Insert antd cssVar to head
const cssVarMatchRegex = /<style data-type="antd-css-var"[\S\s]+?<\/style>/;
const cssVarMatchList = file.content.match(cssVarMatchRegex) || [];

cssVarMatchList.forEach((text) => {
file.content = file.content.replace(text, '');
file.content = file.content.replace('<head>', `<head>${text}`);
});

return file;
}),
);
Expand Down
9 changes: 7 additions & 2 deletions .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ export default defineConfig({
// to avoid generate routes for .dumi/pages/index/components/xx
exclude: [/index\/components\//],
},
ssr: process.env.NODE_ENV === 'production' ? {} : false,
ssr:
process.env.NODE_ENV === 'production'
? {
builder: 'mako',
}
: false,
hash: true,
mfsu: false,
// mako: {},
mako: {},
crossorigin: {},
outputPath: '_site',
favicons: ['https://gw.alipayobjects.com/zos/rmsportal/rlpTLlbMzTNYuZGGCVYM.png'],
Expand Down
3 changes: 3 additions & 0 deletions mako.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"optimization": {
"skipModules": false,
"concatenateModules": false
},
"codeSplitting": {
"strategy": "auto"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"pub": "echo 'Please use `npm publish` instead.'",
"postpublish": "tsx scripts/post-publish.ts",
"presite": "npm run prestart",
"site": "dumi build && cp .surgeignore _site",
"site": "npm i --no-save --legacy-peer-deps [email protected] [email protected] && dumi build && cp .surgeignore _site",
"size-limit": "size-limit",
"sort:api-table": "antd-tools run sort-api-table",
"sort:package-json": "npx sort-package-json",
Expand Down Expand Up @@ -224,7 +224,7 @@
"cross-fetch": "^4.0.0",
"crypto": "^1.0.1",
"dekko": "^0.2.1",
"dumi": "~2.3.8",
"dumi": "~2.4.0",
"dumi-plugin-color-chunk": "^1.1.1",
"esbuild-loader": "^4.1.0",
"eslint": "^8.57.0",
Expand Down

0 comments on commit 3952fd8

Please sign in to comment.