Problem
During SSR hydration, Yew unconditionally re-applies every attribute to the already rendered DOM element. For attributes like src on <img>, setting the attribute again even to the same value - causes the browser to restart the resource fetch, resulting in duplicate network requests.
Steps To Reproduce
- Create a Yew app with SSR + hydration enabled.
- Render an
<img> with a src attribute server-side.
- To make the issue clearly observable, introduce an artificial delay before the WASM bundle is loaded. This ensures the browser has time to fully download the resource from the SSR-rendered HTML before hydration runs and resets the attribute.
- Open DevTools → Network tab before the page loads.
- Load the page and wait for the initial resource fetch to complete.
- Once WASM starts and hydration runs, observe the same resource being fetched a second time.
Expected behavior
During hydration, attributes that already have the correct value on the SSR-rendered DOM element should not be re-applied. No duplicate network requests should occur.
Environment:
- Yew version: master
- Rust version: any
- Target: wasm32-unknown-unknown
- Build tool: trunk / wasm-pack
- OS: any
- Browser and version: any, (FireFox tested)
Root cause (for reference)
packages/yew/src/dom_bundle/btag/mod.rs - the hydrate impl for VTag calls attributes.apply(root, &el) which unconditionally calls el.set_attribute(k, v) for every attribute, regardless of whether the DOM already has that value.
Questionnaire
Problem
During SSR hydration, Yew unconditionally re-applies every attribute to the already rendered DOM element. For attributes like src on
<img>, setting the attribute again even to the same value - causes the browser to restart the resource fetch, resulting in duplicate network requests.Steps To Reproduce
<img>with a src attribute server-side.Expected behavior
During hydration, attributes that already have the correct value on the SSR-rendered DOM element should not be re-applied. No duplicate network requests should occur.
Environment:
Root cause (for reference)
packages/yew/src/dom_bundle/btag/mod.rs- the hydrateimpl for VTagcallsattributes.apply(root, &el)which unconditionally callsel.set_attribute(k, v)for every attribute, regardless of whether the DOM already has that value.Questionnaire