resumable
hydrationの大まかな流れの内の、この辺の部分を省略する
Componentのコードをdownload
Componentのcodeを実行
applicationのstateや、frameworkのstateを復元する
この部分の操作は、server側とclient側で二重で行うことになるので完全に無駄
この部分を省略したrenderingの方法をresumableと呼ぶ
というかBuilder.ioがそう呼んでいる
参考
Hydration is Pure Overhead
hydrationのoverheadについてと、その解決策としてのresumableの解説
記事内では、↑の省略できる3つの手順のことをRECOVERYと呼んでいる
#WIP
https://zenn.dev/aiji42/articles/fafa354f79660d
https://www.builder.io/blog/resumability-from-ground-up
overheadのないhydrationのような
「resumable」という単語だけでは伝わりづらいと思う
hydrationにおけるoverheadを完全に消し去ることの解説
https://qwik.builder.io/docs/concepts/resumable
https://www.builder.io/blog/from-static-to-interactive-why-resumability-is-the-best-alternative-to-hydration
https://gyazo.com/85bc7611687ee8ec9026a60c3bf273ca https://www.builder.io/blog/hydration-is-pure-overhead
https://qwik.builder.io/docs/think-qwik
https://www.builder.io/blog/hydration-is-pure-overhead#:~:text=We'll%20use%20a%20popular%20syntax%20understood%20by%20many%20people%2C%20but%20keep%20in%20mind%20that%20this%20is%20a%20general%20problem%20not%20specific%20to%20any%20one%20framework.
具体例
2つのcomponentからなるcomponentから生成したhtmlはただの2つのbuttonになる
server上でrenderingしたときはここにevent handlerなどもattatchされている
しかし、clientに送るためにserializeする過程で全部消えてただのhtmlになる
Qwikではどうやっているか
RECOVERY部分を排除すればoverheadを消せる
手順
WHAT, WHERE, APP_STATE, FRAMEWORK_STATEを全て含んでserializeしたHTMLを生成する
event handlerをglobalなものとして扱う
event handlerを遅延して回復する
server上でやったことを繰り返す必要がない
これをresumableとよんでいる
eventが呼ばれてからattachする
必要になってからevent handlerを作成する
使われないかもしれないものをコストをかけて全部作るhydartionと異なる点
どんな感じでserializeしているのか
code:html
<div q:host>
<div q:host>
<button on:click="./chunk-a.js#greet">Greet</button>
</div>
<div q:host>
<button q:obj="1" on:click="./chunk-b.js#count0">10</button>
</div>
</div>
<script>/* code that sets up global listeners */</script>
<script type="text/qwik">/* JSON representing APP_STATE, FRAMEWORK_STATE */</script>
このinline scriptの実行はどこで行われるんだ #??
内容によるか
serverで完結するものならclientはzero jsになる
このコード、上の具体例のやつね
code:js
export const Main = () => <>
<Greeter />
<Counter value={10}/>
</>
export const Greeter = () => {
return (
<button onClick={() => alert('Hello World!'))}>
Greet
</button>
)
}
export const Counter = (props: { value: number }) => {
const store = useStore({ count: props.number || 0 });
return (
<button onClick={() => store.count++)}>
{count}
</button>
)
}
メモリ消費量も少ない
event handlerは実行後にメモリ解放する
そうなんだmrsekut.icon
なんでmrsekut.icon