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

[Feature?]: Broaden out event replaying for commonly used input field pattern #1849

Closed
2 tasks done
danieltroger opened this issue Aug 11, 2023 · 2 comments
Closed
2 tasks done
Labels
enhancement New feature or request
Milestone

Comments

@danieltroger
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

On the SSR'd page from solid-js there is a short JS snippet which writes all events into a global object. These are later replayed once the page has hydrated. The reason for doing this, I assume, is that user input given while the page is loading isn't lost.

However, it doesn't seem like that works correctly with a very commonly used input field pattern.

Examples 🌈

According to me this is a very common pattern to do when having an input field that's synced with a signal value.

It seems like that having value={name()} empties the input field before the input events are replayed as the page hydrates - or something else is happening, that leads to the user input to be cleared as the page loads.

My expected behavior is that text entered before the page is hydrated is retained and written to the signal.

function MyComponent() {
  const [name, setName] = createSignal("");

  return (
    <>
      <label for="name">Enter your name </label>
      <input
        id="name"
        placeholder="name"
        value={name()}
        onInput={(e) => setName(e.currentTarget.value)}
      />
      <br />
      <p>Signal value is {JSON.stringify(name())}</p>
    </>
  );
}

Motivation 🔦

Give great UX to my users

@danieltroger danieltroger added the enhancement New feature or request label Aug 11, 2023
@danieltroger
Copy link
Author

Current workaround example that works:

<input
  id={label_id}
  type="text"
  ref={element => {
    const { value } = element;
    if (value) {
      // user typed text on SSR'd page while JS was loading
      props.setConfig("general", "merchant", value);
    }
    createEffect(() => (element.value = props.config.general.merchant));
  }}
  onInput={e => props.setConfig("general", "merchant", e.currentTarget.value)}
/>

@ryansolid
Copy link
Member

Interesting.. I think I've seen this but didn't click on me what was going on. This isn't a Start issue but a dom expressions issue. I will move it to Solid repo.

@ryansolid ryansolid transferred this issue from solidjs/solid-start Aug 11, 2023
ryansolid added a commit that referenced this issue Oct 9, 2023
@ryansolid ryansolid added this to the 1.8.0 milestone Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants