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)
- [email protected] unexpected child ordering with skew based diff HOT 2
- [email protected] application is broken on old user agents HOT 2
- syntax for choosing setting a property vs attribute on elements HOT 9
- useEffect never called HOT 2
- JSX prop works incorrectly on Custom Element, Preact fails to detect JS property setter HOT 5
- [preact/hooks] useMemo keeps recalculating even when the dependency is not changed HOT 2
- JSX type errors on React Bootstrap 2.x & Preact 10.x HOT 6
- Type inference of Omit type not working, CSSProperties in preact/compat HOT 3
- Options debounceRendering and requestAnimationFrame HOT 1
- Support cleanup functions for refs
- Suspense / ErrorBoundary content rendered twice when hydrating with render HOT 1
- Consider bumping version of `@preact/compat` to 18
- RFC: Hydration 2.0 HOT 1
- Aliasing in node refers to the old @preact/compat HOT 2
- Failed to execute insertBefore DOMException happens on rendering list of items HOT 2
- preact demo won't run
- Minified Preact code causing Error by storing event handlers in `l` property on elements causing a name conflict HOT 4
- Wrong typing for HTML translate property HOT 3
- preact cannot be installed from git remote url HOT 2
- Hooks broken in pure browser aka "no build tools route" HOT 2
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.