Repository navigation
Conversation
|
Visit the preview URL for this PR (updated for commit 1a9fd92): https://yew-rs-api--pr4219-master-im3mvlbo.web.app (expires Sat, 14 Nov 2026 11:51:35 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Size ComparisonDetails
✅ None of the examples has changed their size significantly. |
603c1eb to
80cd486
Compare
|
@WorldSEnder Modified. Please review it again. |
There was a problem hiding this comment.
Took a bit, since I am myself not familiar with this part of the library and was hoping Mado would chime in. So bear with and feel free to correct me too.
completed being an (unbounded) hashmap is I believe a memory leak (of all failed requests that never succeed). Keeping the old property of the LRU cache seems worthwhile.
I would phrase the property we want as follows: Every use of the use_linked_state hook has associated with it an input, call this the query. So when the input changes, the query does but it's the same hook. Every query should lead to at most one request to the backend (this is what I understand the bug is about). Multiple simultaneous queries from different uses of the hook for the same input should share the request (only one at best) - implemented by in_flight and refreshing. A query we already answered in SSR should lead to no request (subtly a different hook might have the same query without SSR, this can lead to a query request since cache is unreliable). And finally, memory should be proportional to the hooks used. After unmounting all, only a constant should be left, that's why LRU cache is used but HashMap is used only for things in flight.
The last property I think implies that two different hooks querying for the same input might not always share the result (which could have dropped out of the LRU already) and the hook needs to have a local cache, too.
EDIT: To come back to my earlier comment: each component should remember if a request failed and not retry again. The shared cache should be used only for successful requests.
Sorry this took so long, caching is hard.
|
Note: prior art for request coalescing in rs-singleflight could be helpful. |
|
@WorldSEnder Thanks for spelling out the query lifetime and for the rs-singleflight pointer. I removed the shared completed map. Each hook now keeps the result for its current input, including failures, and the bounded LRU stores only successful values. Initial fetches and explicit refreshes share one in-flight request per key. Hooks that join a request can still read its result after it leaves the in-flight map, even if the LRU entry has been evicted. SSR-prepared results are used directly, and an internal refresh error keeps the previous value visible. I added a browser regression test for request coalescing, explicit retries, and LRU eviction. The updated PR is squashed into one commit and ready for another look. |
Description
Fix the client-side
use_linked_stateretry loop caused by initialLinkError::Internalresults not being cached.Initial fetches now cache all completed results, including infrastructure errors. This allows the suspension to resolve and exposes the error through
LinkedStateHandle::as_result()instead of creating another identical request.Refresh behavior remains unchanged:
LinkError::Internalresults from background refreshes are not cached, so an existing stale value is preserved.Fixes #4218
Checklist