Skip to content

[2.0] A ref's attribute write survives hydration but is overwritten on client creation #3685

Description

@dex157

Describe the bug

A ref that writes an attribute keeps its value after hydration but loses it on client creation. For a value it can't inline, the compiler emits setAttribute after ref, and setAttribute is skipped while hydrating.

import { SIGN_OUT } from "./config";

export const SignOut = () => (
  <a href={SIGN_OUT} ref={el => { el.href = `${SIGN_OUT}?app=${location.origin}`; }}>Sign out</a>
);

@solidjs/compiler 2.0.0-rc.10, generate: "dom":

_$ref(() => { return (el) => { el.href = `${SIGN_OUT}?app=${location.origin}`; }; }, _el$);
_$claimElement(_el$);
_$setAttribute(_el$, "href", SIGN_OUT);

If SIGN_OUT is a literal in the same module, it is folded into the template and the ref wins in both paths.

Your Example Website or App

Minimal component above.

Steps to Reproduce the Bug or Issue

  1. SSR and hydrate a page with <SignOut />: href has ?app=….
  2. Render <SignOut /> on the client, for example after a router navigation: href is the bare SIGN_OUT.

Expected behavior

The same result in both paths, for example with refs running after the element's attributes are applied.

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: solid-js, @solidjs/web and @solidjs/compiler 2.0.0-rc.10

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions