feat: add yew-link crate for unified SSR/CSR data fetching#4027
Open
Madoshakalaka wants to merge 1 commit intomasterfrom
Open
feat: add yew-link crate for unified SSR/CSR data fetching#4027Madoshakalaka wants to merge 1 commit intomasterfrom
Madoshakalaka wants to merge 1 commit intomasterfrom
Conversation
|
Visit the preview URL for this PR (updated for commit 5c337a4): https://yew-rs--pr4027-yew-link-sylkdib6.web.app (expires Sun, 08 Mar 2026 05:38:26 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Benchmark - SSRYew MasterDetails
Pull RequestDetails
|
Size ComparisonDetails
✅ None of the examples has changed their size significantly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #2649, whose lower-level half including
use_prepared_stateanduse_transitive_stateis already shippedThis PR implements the higher-level half of #2649: a
yew-linkcrate that unifies SSR, hydration, and client-side data fetching behind a single hook.The mentioned lower-level hooks already carry server-computed state to the client during hydration. But after that initial page load, client-side navigation requires a completely separate fetch path. This means every data-dependent component needs two code paths stitched together manually.
yew-linkcloses this gap.Implimented new crates proposed in the pr:
yew-linkandyew-link-macroOverhauled
ssr_routerexample, rewired to useyew-linkinstead of generating content inline. Demonstrates#[linked_state],LinkProvider,use_linked_state,Resolver::register_linked, and the axum handler, with full SSR-to-hydration state transfer and client-side nav fetching.See the new website changes to understand the usage pattern
Comparison with Bounce's Query API
@futursolo's Bounce, whose
QueryAPI anduse_prepared_queryhook do overlapping but not identical workyew-link does better on code isolation as its
#[linked_state]stripsresolve()from WASM andQuery::query()body is always compiled into WASM.yew-link also provides better utility by its built-in
linked_state_handlerfor axum.After #4013 merges
#4013 replaces the hand-maintained feature-soundness scripts with
cargo-hack --feature-powerset. Once it lands:yew-linkto thecargo hack clippy -p ...list in.github/workflows/clippy.ymlandpackages/yew/Makefile.tomlso its feature combinations (ssr,hydration,axum) are covered automatically.yew-link,yew-link-macroto--exclude-featuresif any of their features shouldn't participate in the powerset (will check).Remaining TODOs (future PRs)
.refresh()method or TTL-based expiry.use_linked_state_valuethat returnsLoading | Ok | Errinstead of suspending.use_linked_state.(T, input)concurrently should share a single in-flight request.Basically everything else Bounce does correctly
I'm not sure how
cargo releasein our.github/workflows/publish.ymlhandles the two added new crates, but that's a matter for the future when when publish yew-link with yew 0.23Checklist
I have to think about tests.
I manually tested the uphauled ssr_example and paid attention to the network requests. The claims hold well: directly visiting a post by its url receives a server-rendered page. In-app navigation goes through fetch.
E2e testing directly on the example might be a good idea, which requires resolving #196 first.