Coder Social home page Coder Social logo

Comments (6)

farzadbekran avatar farzadbekran commented on June 28, 2024 1

I think I had a similar issue to this, where I was rendering one of two slot components, based on some input to the parent component. Something like this:

  render :: State -> H.ComponentHTML Action ChildSlots m
  render { loginType } =
    case loginType of
      Just (ULC.UL _) -> HH.slot (Proxy :: _ "passwordSlot") unit Pass.form
        unit
        HandlePass
      Just (ULC.Cell cell) -> HH.slot (Proxy :: _ "verificationSlot") unit Ver.form
        cell
        HandleCode
      Nothing -> HH.slot (Proxy :: _ "userloginOrCellSlot") unit ULC.form unit
        HandleULOrCell

which after some interactions and state changes in the parent, which caused the rendered child slot to switch, if I changed the route, (from login page to home page for example), the new page's HTML would be added to the document, but the child slot from the old page would not be removed. I solved it by wrapping the child slots inside a div like this:

  render { loginType } =
    HH.div_
      [ case loginType of
          Just (ULC.UL _) -> HH.slot (Proxy :: _ "passwordSlot") unit Pass.form
            unit
            HandlePass
          Just (ULC.Cell cell) -> HH.slot (Proxy :: _ "verificationSlot") unit
            Ver.form
            cell
            HandleCode
          Nothing -> HH.slot (Proxy :: _ "userloginOrCellSlot") unit ULC.form
            unit
            HandleULOrCell
      ]

My guess is that when a component is to be removed from the document, halogen's diffing algorithm somehow looks for the root node of the component which is to be removed and since it has changed completely (not the same root when it was mounted), it can't find it and the child components remain in the DOM.

So I suggest you wrap your rendered slots inside a div and see if it changes anything for you:

render: \state -> HH.div_ 
  [case state of
      Left a -> html a
      Right a -> slot _nil unit h a Raise]

Not sure if my situation is the same as yours, but I think it's worth a try. Let me know if it works, because I'm not sure if my thinking is correct. If it is, I think it would count as a bug.

from purescript-halogen.

abigailalice avatar abigailalice commented on June 28, 2024 1

I tried wrapping my render functions in a div like the workaround suggested, and it does seem like that fixed it. Thanks.

from purescript-halogen.

garyb avatar garyb commented on June 28, 2024

It's definitely a bug! I thought I'd tagged this issue as such, or that possibly it's a duplicate of another actually, as I've definitely heard about this problem before (using a slot directly inside render causing problems). I think about it quite often, but haven't gotten around to dedicating some time to figuring out how exactly it's going wrong.

from purescript-halogen.

thomashoneyman avatar thomashoneyman commented on June 28, 2024

as I've definitely heard about this problem before (using a slot directly inside render causing problems).

It comes up somewhat often — for example, just a few days ago:
thomashoneyman/purescript-halogen-store#17

(the halogen-store connect component is a higher-order component that just renders a slot directly)

And perhaps it relates to this?
#748

from purescript-halogen.

garyb avatar garyb commented on June 28, 2024

Thanks for the links 👍, I knew it definitely happened in relation to -store as that's where I remember hearing about it first, but you could well be right that it's related to the other thing with memoized too.

from purescript-halogen.

garyb avatar garyb commented on June 28, 2024

The other issues that are probably this are #766 and #657

from purescript-halogen.

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.