Comments (5)
@sylsaint React's reuse of the DOM node here is expected given the reconciliation algorithm's specifications and constraints, and the way you've structured your JSX. You're returning the same VDOM structure each time with a <button>
in the same place, but only the attributes on it are different.
The docs go into a lot of depth on this sort of scenario https://react.dev/learn/preserving-and-resetting-state
from react.
The corresponding no-framework code:
<form><button type="button">Click me</button></form>
document.querySelector("button").addEventListener("click", e => { e.target.setAttribute("type", "submit"); });
will do the exact same thing and also fire the submit event. So isn't this the intended behavior? If it's not what you want, your proposed workaround with key
is probably the cleanest.
from react.
Hm yea this seems confusing but matches how the DOM works. I think I'll close this.
from react.
@nmain Your code is based on the the same DOM node, it's ok. But in react they are actually different node, during render process, react reuse last DOM node, just modify its properties.
from react.
@gaearon Yes, it's confusing. But actually it's caused by react that reused the same DOM node for different buttons.
from react.
Related Issues (20)
- [React 19] Inconsistent "cache" api with Async Operations in react-server HOT 2
- [Compiler Bug]: Increment expression in for-loop loses assignment operation HOT 4
- Bug: TypeError: Cannot read properties of null (reading 'useState')
- Ensures role attribute has an appropriate value for the element (aria-allowed-role - https://dequeuniversity.com/rules/axe/4.7/aria-allowed-role?application=msftAI) HOT 1
- Ensures ARIA attributes are allowed for an element's role (aria-allowed-attr - https://accessibilityinsights.io/info-examples/web/aria-allowed-attr)Bug: HOT 1
- Bug: HOT 1
- [VLG]¿Cómo hablar con Vueling por teléfono? @telefono españa HOT 1
- hook invalid
- Feature request: Expose additional profiling tools for library testing HOT 6
- Bug: "Should have a queue. This is likely a bug in React" HOT 11
- [React 19]
- [React 19] requestFormReset reports TypeError Cannot read properties of null (reading 'queue') on repeated form submissions HOT 4
- [Compiler Bug]: healthcheck do not check next.js StrictMode HOT 5
- [React 19] Different behaviors with `preload` method HOT 2
- Bug: React 18 SSR Sometimes fallback to CSR without throw any errors on Prod Mode, The fiber node which tag is "HostRoot"(3)has flags "Snapshot"(1024),it works fine when flags is Update(4) HOT 1
- Bug: ForwardRef components cant have display names or types HOT 2
- Consider changing the next property type of the update object of the dispatchSetState function from any to null
- [React 19]
- ..
- [DevTools Bug]: 5.2.0 is not available for Firefox HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react.