Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hydration duplicates interpolated variables #319

Closed
arctic-hen7 opened this issue Dec 15, 2021 · 1 comment · Fixed by #321 or #374
Closed

Hydration duplicates interpolated variables #319

arctic-hen7 opened this issue Dec 15, 2021 · 1 comment · Fixed by #321 or #374
Labels
C-bug Category: bug, something isn't working
Milestone

Comments

@arctic-hen7
Copy link
Contributor

Describe the bug
When hydrating a view rendered with SSR, any interpolated variables will be duplicated at the element-level.

To Reproduce
Steps to reproduce the behavior:

  1. Create a component that interpolates any variable.
  2. Prerender that component with SSR using sycamore::render_to_string().
  3. Inject that string into the <body> of your page with web_sys.
  4. Hydrate the component with sycamore::hydrate().
  5. Observe that the interpolated value is duplicated at the element level (e.g. Hello World!Hello World!).

This can also be observed in Perseus from v0.3.0-beta.22 by creating a page that interpolates a value and then enabling the hydrate feature, which enables Sycamore's hydration (and follows a very similar process to that described above).

Expected behavior
Interpolated values should be removed, recomputed, and rendered without duplication.

Screenshots
If applicable, add screenshots to help explain your problem.

Interpolated value duplication

Environment

  • Sycamore: v0.7.0
  • Browser: Firefox 96.0b4
  • OS: Ubuntu

Additional context
An MRE for this issue is available here. Use trunk serve to run it and observe the issue in a browser.

I assume this is caused by simply not removing the old interpolated values, which I understand would be difficult without knowing exactly what they are. My (perhaps very naive) suggestion would be to identify the smallest number of elements within a component that have interpolated values, and then remove those, recomputing the new values. Alternatively, a more nuanced approach could be taken of isolated interpolated values within strings etc., though this may have a large runtime performance cost (but I'm unfamiliar with this part of the Sycamore codebase, so I honestly have no idea).

@arctic-hen7 arctic-hen7 added the C-bug Category: bug, something isn't working label Dec 15, 2021
@lukechu10 lukechu10 reopened this Dec 28, 2021
@lukechu10
Copy link
Member

This has been fixed for dynamic nodes that are children of elements, e.g.

view! {
    div {
        (dynamic_value)
    }
}

but doesn't work for dynamic nodes at the top-level, e.g.

view! {
    (dynamic_value)
}

This proved to be a much harder problem to solve and would probably require a lot of refactors so it's nothing I can fix quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug, something isn't working
Projects
None yet
2 participants