dai-shi / waku

⛩️ The minimal React framework
https://waku.gg
MIT License
4.72k stars 125 forks source link

server components (even dynamic) runs on build unexpectedly (through `unstable_collectClientModules`) #543

Open himself65 opened 9 months ago

himself65 commented 9 months ago

See: https://github.com/himself65/waku/commit/5e8218f33fb1a7b9ec1ead5d9ce665f8199b75ac

/Users/himself65/Library/Caches/fnm_multishells/48575_1709013514281/bin/pnpm run build

> waku-starter@0.1.0 build /Users/himself65/Code/waku/examples/01_template
> DONT_LEAK_IN_BUILD_TIME=NO waku build

vite v5.1.4 building SSR bundle for production...
✓ 42 modules transformed.
✓ built in 374ms
vite v5.1.4 building SSR bundle for production...
✓ 43 modules transformed.
dist/assets/root-layout-BDx5PYJp.css              11.64 kB
dist/assets/rsc1-ddb75831a.js                      0.15 kB
dist/components/header.js                          0.45 kB
dist/components/counter.js                         0.48 kB
dist/components/error-boundary.js                  0.51 kB
dist/templates/contact-page.js                     0.53 kB
dist/components/footer.js                          0.71 kB
dist/templates/about-page.js                       1.06 kB
dist/templates/root-layout.js                      1.16 kB
dist/templates/home-page.js                        1.16 kB
dist/assets/jsx-runtime.react-server-DaQipseb.js   1.25 kB
dist/assets/rsc2-19056431e.js                      1.99 kB
dist/assets/rsc0-1f451937d.js                      2.67 kB
dist/assets/react.react-server-BRc6Y66K.js        10.76 kB
dist/entries.js                                   12.98 kB
dist/rsdw-server.js                               41.09 kB
✓ built in 106ms
vite v5.1.4 building for production...
✓ 40 modules transformed.
dist/public/index.html                        1.01 kB │ gzip:  0.45 kB
dist/public/assets/rsc0-1f451937d.js          0.21 kB │ gzip:  0.17 kB
dist/public/assets/rsc1-ddb75831a.js          0.42 kB │ gzip:  0.31 kB
dist/public/assets/jsx-runtime-CcapePxT.js    0.63 kB │ gzip:  0.42 kB
dist/public/assets/main-A3kPowAf.js           0.73 kB │ gzip:  0.46 kB
dist/public/assets/indexHtml-DVWfb-0O.js      0.86 kB │ gzip:  0.49 kB
dist/public/assets/rsc2-19056431e.js          4.24 kB │ gzip:  1.80 kB
dist/public/assets/index-XTTFb40S.js          8.09 kB │ gzip:  3.06 kB
dist/public/assets/client-C95rG-dh.js       191.17 kB │ gzip: 60.21 kB
✓ built in 303ms
Error: SHOULD NOT LEAK
    at ContactPage (file:///Users/himself65/Code/waku/examples/01_template/dist/templates/contact-page.js:9:11)
    at ib (file:///Users/himself65/Code/waku/examples/01_template/dist/rsdw-server.js:573:7)
    at jb (file:///Users/himself65/Code/waku/examples/01_template/dist/rsdw-server.js:592:46)
    at Q (file:///Users/himself65/Code/waku/examples/01_template/dist/rsdw-server.js:711:16)
    at Object.toJSON (file:///Users/himself65/Code/waku/examples/01_template/dist/rsdw-server.js:629:15)
    at stringify (<anonymous>)
    at nb (file:///Users/himself65/Code/waku/examples/01_template/dist/rsdw-server.js:831:53)
    at kb (file:///Users/himself65/Code/waku/examples/01_template/dist/rsdw-server.js:859:7)
    at Timeout._onTimeout (file:///Users/himself65/Code/waku/examples/01_template/dist/rsdw-server.js:896:12)
    at listOnTimeout (node:internal/timers:573:17)

Process finished with exit code 0

Also exit code shouldn't be 0

dai-shi commented 9 months ago

Thanks for opening up an issue. Yeah, it seems like a bug. Can you dig into it? exit status 0 is also weird.

himself65 commented 9 months ago

exit status 0 is also weird.

Working on this

himself65 commented 9 months ago

Working on this

dai-shi commented 9 months ago

From what I understand https://github.com/dai-shi/waku/issues/536#issuecomment-1966721276, dist/public/index.html isn't created if / is not isStatic. So, I don't see how this happens. Hope you find a bug somewhere.

himself65 commented 9 months ago

inside unstable_collectClientModules

dai-shi commented 9 months ago

From #573, what I'd say is it's not SSR (html generation) and it's a false positive (not leaking). So, I don't consider it's a bug per se. However, I agree it's not a desirable behavior and I wish we could come up with a different solution and eliminate unstable_.

dai-shi commented 9 months ago

btw, do you have a real issue with the current non-ideal behavior?

himself65 commented 9 months ago

btw, do you have a real issue with the current non-ideal behavior?

Yeah, I will use getEnv in the runtime, there's no env var during my build time

dai-shi commented 9 months ago

I see. It's unfortunate, but the current workaround would be add a check if such an env var is available or not (and do some fallback that would never be required in the runtime.)

dai-shi commented 7 months ago

Current status: https://github.com/dai-shi/waku/pull/573#discussion_r1514091960

dai-shi commented 1 month ago

Can we statically analyze the code?

I was just thinking about it. Analyzing statically is not possible with current architecture. defineRouter & createPages are designed to isolated from filesystem.

himself65 commented 1 month ago

I hope there's a enviroment like WAKU_STAGE === 'build' or globalThis.cleanup(fn) to make sure I can disconenct the database or ignore some SSR

dai-shi commented 1 month ago

Try unstable_getPlatformObject for now.

https://github.com/dai-shi/waku/blob/82dea924457fba1c60a9dfb071cb69dc44d7bbf2/packages/waku/src/server.ts#L38-L43

We might be missing something for emit....