Comments (6)
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.
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.
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.
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.
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.
The other issues that are probably this are #766 and #657
from purescript-halogen.
Related Issues (20)
- `tellAll` function is not re-exported in Halogen module
- Enabling `StateT` with `HalogenM` HOT 1
- Export tellAll from Halogen.Query to Halogen HOT 2
- Reading Effects chapter -> Could not match type ResponseFormat String with type AffjaxDriver HOT 4
- Question: how to handle events coming from a js app? HOT 2
- Communication with JS loaded via CDN HOT 2
- `raise` should not be a blocking operation HOT 8
- Discussion: CSS strategy for halogen applications HOT 20
- Question: body-level events HOT 3
- Order of properties matters when using `value` with `min` / `max` for `InputRange` HOT 3
- Change kind of slots to not be `Type`
- `RenderSpec` doc comment still mentions `h` parameter
- Doc: the examples of "An Aff Example: HTTP Requests" give TypesDoNotUnify Error on Halogen v7 HOT 1
- Select Multiple Selected does not work HOT 4
- A bug? Weird behavior of text input fields. HOT 4
- Child component is destroyed while parent component handles output from that child HOT 5
- Array state updates HOT 4
- open and showModal are missing for dialog HOT 6
- The Component type should have role annotations
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 purescript-halogen.