Coder Social home page Coder Social logo

Comments (7)

linzhe141 avatar linzhe141 commented on July 17, 2024 1

However, it is reactive when used in a template?

The componentUpdateFn of the component will update the slots and execute the render function when it is re-executed, so the slots in the render function are the updated slots.

image

image

from core.

skirtles-code avatar skirtles-code commented on July 17, 2024 1

There was a similar issue opened recently, #11227. The description of the problem is different, as is the use case, but I believe the underlying cause is the same: the slots object isn't reactive and is being used outside the rendering of its owner component.

I'm wondering whether the decision to make the slots object non-reactive should be re-evaluated. I think it made sense back in a Vue 2 Options API context, but maybe it isn't such a good fit for where Vue is now?

It feels similar to $refs and $attrs. Previously they were just plain objects, but that didn't work well with the Composition API, so they've both been 'replaced' by alternatives that support reactivity, or at least partial reactivity.

I assume the reason it isn't reactive is because of the extra overhead, but is that really significant enough to worry about if it makes slots more difficult to use in more advanced use cases?

I also wonder whether making slots reactive might benefit Vapor mode.


Bit of a tangent, but more generally I wonder whether the current approach of forcing a child to re-render when the props or slots change is actually the best way to go. While I can understand why it was done that way, it is a problem I've hit a few times and it can be really difficult to work around.

Perhaps, rather than always forcing a re-render, it could check whether the relevant job has been added to the scheduler queue and only do the re-render if it has? That approach might already be viable for props, though for slots it would need reactivity adding to the slots object.

from core.

linzhe141 avatar linzhe141 commented on July 17, 2024

Because instance's slots is not a reactive object, but a normal object

image

from core.

geiregjo avatar geiregjo commented on July 17, 2024

However, it is reactive when used in a template?

from core.

LinusBorg avatar LinusBorg commented on July 17, 2024

However, it is reactive when used in a template?

It's not, actually. When the parent changes the number of slots it passes down, it tells that child component "hey, you need to re-render". And during that re-render, triggered by the parent component, not by the slots object, you read the sot object's properties again. That's why they are updated in the template.

from core.

geiregjo avatar geiregjo commented on July 17, 2024

Ok, I'll use onBeforeUpdate to detect slot changes then.

Just wondering, is this worth a feature request?

from core.

yyx990803 avatar yyx990803 commented on July 17, 2024

closing as a duplicate of #11227 as the root cause is the same.

from core.

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.