Comments (7)
Hmm - interesting case here. The semantics of that third argument to render()
are currently "existing rendered version to update in-place", which is why it doesn't remove the mismatched node. This might be something we need to do a poll about. Good find!
from preact.
it actually works fine if the span is not wrapped in a component: http://jsfiddle.net/ext7nm02/1/
from preact.
Ahh, good hunting - I think that means we can call this a bug :)
from preact.
Was bit by this today when building preact-portal.
My workaround for now is to use a proxy component that returns what you want:
class Proxy extends Component {
render({ children }) {
return children[0];
}
}
let r = render(<Proxy><Comp /></Proxy>, document.body, r);
r = render(<Proxy><span /></Proxy>, document.body, r);
r = render(<Proxy><Comp /></Proxy>, document.body, r);
from preact.
I believe I have discovered the issue. Preact's diff algorithm tries very hard to retain all state in locals rather than relying on things like Array.prototype.length (for performance). When a keyed VNode
is determined to be unused during diff, it gets appended to a list of children that are reclaimed at the end of the diff. However, there was a conditional around the reclamation to avoid operating on empty sparse Arrays, and one of the values was not being updated to reflect newly orphaned keyed VNodes.
In the screenshot below (from @andrewn's Codepen repro), the value of childrenLen
is correctly updated to be 1
(one orphaned VNode), however, the value of min
is left unmodified after diffing, which means it remains as 1
. This meant Preact was skipping removal of the VNode entirely.
I'll get a fix in right away, but I want more tests around keys in order to cover edge cases like this.
Thanks to both of you for your help!
from preact.
@kruczy Thanks again for your repro. I just released 4.1.2, and have included your JSFiddle as a new test.
Here is your repro running against Preact 4.1.2
showing the intended behavior: JSFiddle.
from preact.
Great 👍 Thanks!
from preact.
Related Issues (20)
- Missing typescript types for MathML HOT 2
- Make render-function curried HOT 5
- Component don't rerender if prop changes in short period of time HOT 3
- 10.18 regression: setState triggers DOMException: Node.insertBefore: Child to insert before is not a child of this node HOT 12
- Radix UI / Select component in preact HOT 1
- `useId` generates duplicate identifiers in some cases when calling `render` from `@preact/compat` multiple times HOT 3
- Request: setProperty() Export HOT 2
- Add `x_google_ignoreList` (Ignore-listing code) support to sourcemaps HOT 11
- Incorporate preact to NEXTJS. HOT 3
- Focus lost when moving child with `key` HOT 3
- [preact/compat] onTouchMoveCapture not processed
- TS errors for contentEditable attribute
- Aliasing React to Preact in Deno HOT 9
- "Cannot read properties of null (reading '__H')" when hydrating a component in the browser HOT 1
- (question)Is there any practical example of purely using CDN? HOT 5
- TypeError: undefined is not an object (evaluating 'this.l[e.type+!1]') HOT 1
- preact+react-modal,Uncaught TypeError: Cannot read properties of null (reading '__H') HOT 9
- Island architecture with partial hydration HOT 3
- preact renders only one iframe if more than one iframe provided to dangerouslySetInnerHTML HOT 2
- When the value of setState remains unchanged, the state-driven controlled component, such as <input/>, seems to no longer be under the influence of the state. HOT 1
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 preact.