Content-Length: 242964 | pFad | https://github.com/purescript-halogen/purescript-halogen/issues/657

2E Unexpected behavior with child components with a single slot · Issue #657 · purescript-halogen/purescript-halogen · GitHub
Skip to content

Unexpected behavior with child components with a single slot #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
marcusbuffett opened this issue May 24, 2020 · 1 comment
Open

Unexpected behavior with child components with a single slot #657

marcusbuffett opened this issue May 24, 2020 · 1 comment
Labels

Comments

@marcusbuffett
Copy link

Recently encountered an issue with child components that just slot in other components. Here's what the component tree looks like:

- Router component
  - Slot "home"
    - Home component
      - Slot "innerHomeComponent"
        - Inner home component
  - Slot "about"
    - About component
      - Slot "innerAboutComponent"
        - Inner about component

In the router, the "home" and "about" slots should never both be rendered, like
this:

  render { route } = do
    HH.div [ class_ (ClassName "should-only-have-one-child") ]
      [ case route of
          Just r -> case r of
            Home -> HH.slot (SProxy :: _ "home") 0 Home.component unit absurd
            About -> HH.slot (SProxy :: _ "about") 1 About.component unit absurd
          Nothing -> HH.div_ [ HH.text "Oh no! That page wasn't found." ]
      ]

But after routing from home to about, I get both home and about rendered in the
.should-only-have-one-child div.

What's triggering the issue is that the Home/About components that the router is
rendering are just slots for their "inner" components. In the example this
doesn't make much sense but in my real code I have that outer component
providing some input to the child component (the parent component is sorta like
the redux connect HOC in react).

Wrapping the inner component's slot in a div fixes the issue:

-    Hooks.pure $ HH.slot _innerComponent unit innerComponent unit absurd
+    Hooks.pure $ HH.div [] [ HH.slot _innerComponent unit innerComponent unit absurd ]

Anyway, I'm sure this hasn't done a great job of explaining the issue, I made a
repo with a reproduction of the issue: https://github.com/marcusbuffett/halogen-slots-issue

And here's a PR with the div fix mentioned above: https://github.com/marcusbuffett/halogen-slots-issue/pull/2/files

The example code does use hooks, but it's not a hooks issue, converting the parent components to "plain" components causes the same issue.

@BebeSparkelSparkel
Copy link
Contributor

Slots have always behaved a bit strange for me and this brings to light a lot of issues I have had with them. I thought it was me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/purescript-halogen/purescript-halogen/issues/657

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy