rspress
rspress copied to clipboard
[Bug]: plugin-preview components that don't support SSR would break the SSG build due to sideEffects
Version
System:
OS: macOS 14.2.1
CPU: (10) arm64 Apple M1 Max
Memory: 94.38 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Browsers:
Chrome: 120.0.6099.216
Chrome Canary: 122.0.6250.0
Safari: 17.2.1
npmPackages:
@rspress/plugin-preview: latest => 1.9.3
rspress: ^1.0.0 => 1.9.3
Details
docs/guide/index.mdx
# Error
```tsx
console.log(window) <---- break the SSG build
function App() {
return (
<div>
<span>Hello World</span>
</div>
);
}
export default App;
\```
Solutions
I came up with three solutions
-
rspress-plugin-preview support the components with sideEffect in some way
-
Add error messages to encourage users to improve the quality of their components to support SSR.
-
Add error messages to let users who temporarily cannot resolve component SSR support turn off the
ssg: false
Reproduce link
https://github.com/SoonIter/rspress-preview-demo
Reproduce Steps
pnpm i
npm run build
cc @10Derozan
It has been fixed in #578
<code src="./A.tsx"/> still have this problem.
# mdx
<code src="./Comp.tsx" />
// Comp.tsx
console.log(window)
const A = () => <div>12321</div>
export default A;
We can use await import to solve it
<code src="./Comp.tsx" />
⬇️
const Comp = React.lazy(() => import('./Comp.tsx'));