Conversation
don't start fetching once per component, cache the vtable.
|
The review pings are mostly because I think both of you will find this interesting, not necessarily as an invite to dig into the code and give meaningful suggestions for improvements (but feel free to if you have the time). |
makes it possible to implement a helper macro without the user pulling in an extra dependency and has tighter version requirements.
Benchmark - coreYew MasterPull Request |
Benchmark - SSRYew MasterDetails
Pull RequestDetails
|
|
Visit the preview URL for this PR (updated for commit 3cf0e6e): https://yew-rs-api--pr3932-split-wasm-8cld9gqn.web.app (expires Wed, 29 Oct 2025 11:11:55 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
| let suspension = Suspension::from_future(async move { | ||
| // Ignore error in case receiver was dropped | ||
| let vtable = C::fetch().await; | ||
| let comp = (vtable.imp.create)(&creation_ctx); |
There was a problem hiding this comment.
This creates the underlying component with creation_ctx, whose link() returns inner_scope. But inner_scope is never mounted — its state is permanently None.
This makes function component hooks permanently broken after load.
When a function component is created, FunctionComponent::new() captures ctx.link().clone() into a re_render closure:
let re_render = {
let link = ctx.link().clone(); // this is inner_scope
Rc::new(move || link.send_message(()))
};Every hook (use_state, use_reducer, etc.) shares this closure. When a state setter fires, it calls inner_scope.send_message(()), which schedules an UpdateRunner. But UpdateRunner::run() checks inner_scope.state, finds None, and silently returns. The component renders once correctly and then becomes completely unresponsive to all state changes. I've confirmed this — a simple use_state counter wrapped in declare_lazy_component! renders 0 and clicking the increment button does nothing.
I created a minimal reproducing repo https://github.com/Madoshakalaka/yew-lazy-hook-bug
Description
Add a way to split the wasm bundle in multiple components. This modifies the build process, and uses relocation information emitted by llvm to identify where to "split". There's a bit of glue code in yew to ensure that messages sent to the lazy component are processed and properties are passed along without additional cloning.
The main part of the solution lives in https://github.com/WorldSEnder/wasm-split-prototype as of now. This was implemented in collaboration with the maintainer of leptos.
Checklist