Giter VIP home page Giter VIP logo

Comments (7)

developit avatar developit commented on May 1, 2024

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.

kruczy avatar kruczy commented on May 1, 2024

it actually works fine if the span is not wrapped in a component: http://jsfiddle.net/ext7nm02/1/

from preact.

developit avatar developit commented on May 1, 2024

Ahh, good hunting - I think that means we can call this a bug :)

from preact.

developit avatar developit commented on May 1, 2024

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.

developit avatar developit commented on May 1, 2024

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.

screen shot 2016-03-09 at 10 49 42 am

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.

developit avatar developit commented on May 1, 2024

@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.

kruczy avatar kruczy commented on May 1, 2024

Great 👍 Thanks!

from preact.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.