dai-shi / waku

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

(router) improve static pages #885

Open dai-shi opened 4 days ago

dai-shi commented 4 days ago

Background

The two rendering types "static" and "dynamic" are very complicated because there are two aspects RSC and SSR.

This isStatic is for RSC: https://github.com/dai-shi/waku/blob/9ca5161cfba93e402641249a494642a912d25795/packages/waku/src/server.ts#L16

This `isStatic is for SSR: https://github.com/dai-shi/waku/blob/9ca5161cfba93e402641249a494642a912d25795/packages/waku/src/server.ts#L12

Currently, isStatic for SSR will be true if all of isStatic for RSC are true.

Expectation

If we mark a "page" or a "layout" to be "static", our expectation is that the rendering only happens just once. (For PRD, only at the build time, and for DEV only the first time and again after hot reload.)

Actual problem

If we mix "static" and "dynamic" for RSC, the page for SSR will be "dynamic" which is expected, but then RSC's "static" isn't truly static.

In the 01_template, modify _layout.tsx to be "dynamic", while keeping "static" in pages.tsx. Now, HomePage in page.tsx renders more than expected. In addition to the build time, it renders on production. It only behaves like "static" on client routing thanks to shouldSkip mechanism.

Solution

Challenges

dai-shi commented 4 days ago

@tylerlaws0n here's the first write-up.