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

The ref to the element in the use:* function is missing some attributes #2371

Open
neyrokach opened this issue Nov 26, 2024 · 1 comment
Open

Comments

@neyrokach
Copy link

Describe the bug

If you set some attributes of an element via an expression ({ }), then this value will be missing in the ref in the use:* function. The problem is that the code in the expression is executed after the use:*function.

In the given example, the check() is executed for two inputs. For the first one the name is set from the props and output will be "Name: ". For the second one the output text is correct ("Name: Second input").

function check(ref) {
  console.log('Name: ', ref.name);
}

function Input(props) {
  return (
    <div style="display:flex;flex-direction:column;gap:1rem">
      <input type="input" name={props.name} placeholder="Message" use:check />
      <input type="input" name="Second input" placeholder="Message" use:check />
    </div>
  );
}

export default function App() {
  return <Input name="First input" />;
}

Your Example Website or App

https://stackblitz.com/edit/solidjs-templates-prrjc7?file=src%2FApp.jsx

Steps to Reproduce the Bug or Issue

https://stackblitz.com/edit/solidjs-templates-prrjc7?file=src%2FApp.jsx

Expected behavior

I assume that the execution of the function in use:* should be after execution of all expressions

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Google Chrome

Additional context

No response

@neyrokach neyrokach changed the title The ref to the element in the use:*` function is missing some attributes The ref to the element in the use:* function is missing some attributes Nov 26, 2024
@ryansolid
Copy link
Member

This is a timing issue. Technically use: and ref happen at element creation but before apply reactive attributes, children or mounting. This is so they can be passed through to child elements as a stable reference. The recommended solution to this is typically to use onMount to ensure everything is present. Admittedly for use not waiting seems less valuable in most cases but this also makes it consistent with the rest of the lifecycle.

So this is by design but I can see why it isn't intuitive.

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

No branches or pull requests

2 participants