rspress icon indicating copy to clipboard operation
rspress copied to clipboard

[Bug]: plugin-preview components that don't support SSR would break the SSG build due to sideEffects

Open SoonIter opened this issue 1 year ago • 4 comments

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

image
 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

  1. rspress-plugin-preview support the components with sideEffect in some way

  2. Add error messages to encourage users to improve the quality of their components to support SSR.

  3. 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

SoonIter avatar Jan 16 '24 15:01 SoonIter

cc @10Derozan

sanyuan0704 avatar Jan 17 '24 02:01 sanyuan0704

It has been fixed in #578

10Derozan avatar Feb 19 '24 03:02 10Derozan

<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;

SoonIter avatar Apr 23 '24 14:04 SoonIter

We can use await import to solve it

<code src="./Comp.tsx" />
⬇️
const Comp = React.lazy(() => import('./Comp.tsx'));

SoonIter avatar May 13 '24 16:05 SoonIter