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

in-place updates (rendering optimizations) not working for input component #336

Open
lsimone opened this issue Mar 30, 2023 · 1 comment

Comments

@lsimone
Copy link

lsimone commented Mar 30, 2023

I created a minimal commented react codesandbox to clearly show expected and actual outcome.

I read what you documented about in-place updates but I did not find much information.

Here I can read:

With signals we can bypass Virtual DOM rendering and bind signal changes directly to DOM mutations. If you pass a signal into JSX in a text position, it will render as text and automatically update in-place without Virtual DOM diffing:

Maybe input's value is not considered to be "a text position" so behavior I experienced is consistent and in that case I would like to ask you if you think you will support in-place update for this in the future;

otherwise, my codesandbox (I left a comment trying to be as clear as possible) shows that when using <input value={whateverStringSignal}>, your component will re-render and it cannot count on optimizations.

In both cases: is there a way to achieve this with signals (and some custom code maybe) right now?

References:

@JoviDeCroock
Copy link
Member

JoviDeCroock commented Mar 30, 2023

I don't think this is possible in React with how controlled components and stuff interact, luckily the DOM itself already behaves that way when you use the default behavior! Typing in an input only reflects in JS when you bind the onChange and perform setState calls. Libraries like react-hook-form already use this to do performant updates.

These optimizations however should work in Preact 😅 https://codesandbox.io/s/restless-rgb-qvxdhl?file=/src/index.js

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