Skip to content

fix(yew-link): surface initial internal fetch errors instead of retrying indefinitely - #4219

Open
cuishuang wants to merge 1 commit into
yewstack:masterfrom
cuishuang:master
Open

cuishuang wants to merge 1 commit into
yewstack:masterfrom
cuishuang:master

Conversation

@cuishuang

@cuishuang cuishuang commented Sep 7, 2026 •

Copy link
Copy Markdown

Description

Fix the client-side use_linked_state retry loop caused by initial LinkError::Internal results 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::Internal results from background refreshes are not cached, so an existing stale value is preserved.

Fixes #4218

Checklist

  • I have reviewed my own code
  • I have added tests

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 80cd486):

https://yew-rs-api--pr4219-master-68tx4rnl.web.app

(expires Tue, 15 Sep 2026 13:14:45 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Size Comparison

Details
examples master (KB) pull request (KB) diff (KB) diff (%)
async_clock 100.206 100.206 0 0.000%
boids 164.938 164.938 0 0.000%
communication_child_to_parent 93.710 93.710 0 0.000%
communication_grandchild_with_grandparent 105.993 105.993 0 0.000%
communication_grandparent_to_grandchild 102.314 102.314 0 0.000%
communication_parent_to_child 91.101 91.101 0 0.000%
contexts 106.300 106.300 0 0.000%
counter 86.271 86.271 0 0.000%
counter_functional 88.302 88.302 0 0.000%
dyn_create_destroy_apps 90.170 90.170 0 0.000%
file_upload 98.577 98.577 0 0.000%
function_delayed_input 94.617 94.617 0 0.000%
function_memory_game 168.581 168.581 0 0.000%
function_router 400.298 400.298 0 0.000%
function_todomvc 164.981 164.981 0 0.000%
futures 235.946 235.946 0 0.000%
game_of_life 100.623 100.623 0 0.000%
immutable 258.612 258.612 0 0.000%
inner_html 80.781 80.781 0 0.000%
js_callback 109.758 109.758 0 0.000%
keyed_list 176.339 176.339 0 0.000%
mount_point 84.192 84.192 0 0.000%
nested_list 112.731 112.731 0 0.000%
node_refs 91.776 91.776 0 0.000%
password_strength 1765.649 1765.649 0 0.000%
portals 93.599 93.599 0 0.000%
router 366.529 366.529 0 0.000%
suspense 113.938 113.938 0 0.000%
timer 88.518 88.518 0 0.000%
timer_functional 99.423 99.423 0 0.000%
todomvc 141.977 141.977 0 0.000%
two_apps 86.176 86.176 0 0.000%
web_worker_fib 136.490 136.490 0 0.000%
web_worker_prime 186.573 186.573 0 0.000%
webgl 82.927 82.927 0 0.000%

✅ None of the examples has changed their size significantly.

Comment thread packages/yew-link/src/lib.rs Outdated
@cuishuang

Copy link
Copy Markdown
Author

@WorldSEnder Modified. Please review it again.

@WorldSEnder WorldSEnder left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@WorldSEnder

Copy link
Copy Markdown
Member

Note: prior art for request coalescing in rs-singleflight could be helpful.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use_linked_state retries indefinitely after an initial LinkError::Internal

2 participants