sycamore icon indicating copy to clipboard operation
sycamore copied to clipboard

DOM assets are reloaded after hydration

Open danielnehrig opened this issue 3 years ago • 4 comments

Describe the bug after hydration takes place assets are reloaded. for instance images are loaded twice due to this resulting in longer load times.

To Reproduce Steps to reproduce the behavior:

  1. hydrate with a image in the dom

Expected behavior We do not do another redundant network call

Screenshots bug

Environment

  • Sycamore: 0.8.2
  • Browser: chrome
  • OS: linux

danielnehrig avatar Oct 18 '22 18:10 danielnehrig

workaround is to set a cache control header so the images are not fetched again but reused.

danielnehrig avatar Oct 18 '22 18:10 danielnehrig

No clue really, but could you hypothetically fix this by having all your assets in a non-Sycamore place and then using the shadow DOM to tunnel them through? A component for this shouldn't be impossible as an interim workaround...

arctic-hen7 avatar Oct 18 '22 20:10 arctic-hen7

The problem is that the attribute is being re-set (difference from reset) during hydration which causes the resource to be fetched again. If cache is disabled, that triggers another network request but if cache is enabled, the browser is usually smart enough to just reuse the previous fetched data.

lukechu10 avatar Oct 18 '22 20:10 lukechu10

A really simple fix might just be to make the following code only run when hydration has completed, just like what is being done in HydrateNode::append_child. https://github.com/sycamore-rs/sycamore/blob/abd556cbc02047042dad2ebd04405e455a9b11b2/packages/sycamore-web/src/hydrate_node.rs#L170-L173

To test that this the attribute is not actually being overwritten during hydration, we could purposefully render something different for the attribute during SSR and compare whether the final attribute after hydration has changed (it should not).

However, once #19 is (finally) implemented, these kinds of bugs should become trivial to fix.

lukechu10 avatar Oct 19 '22 19:10 lukechu10