Skip to content

Show with a callback with no params is getting re-computed #869

Closed

Description

@mdynnl

Describe the bug

Show with a callback with no params is getting re-computed if a signal used in when is also used before or after with jsx expression {signal()}

Your Example Website or App

https://playground.solidjs.com/?hash=1389243964&version=1.3.7

Steps to Reproduce the Bug or Issue

  1. Go to the linked playground
  2. Click the button a few times. The inner function creation should log and should not log any further
  3. Un-comment line 12 or 20
  4. Click the button again a couple times. There'll be create, cleanup logs whenever the button is clicked

Expected behavior

Step 4 should behave the same as Step 2

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

I also reported this in discord server https://discord.com/channels/722131463138705510/751355413701591120/947858138315505724

Activity

  1. otonashixav commented on Feb 28, 2022

    @otonashixav
    Contributor

    I think this is related to components wrapped in a thunk within fragments rather than Show. Show passes through props.children when it is a function with no parameters, allowing the bug to take effect. If you replace the fragment with a div in the example given, the issue disappears. If you remove the Show component completely, leaving just {() => <Inner />}, the issue persists.

    Minimal reproduction showing this: https://playground.solidjs.com/?hash=-12796868&version=1.3.7

  2. mdynnl commented on Feb 28, 2022

    @mdynnl
    ContributorAuthor
  3. mdynnl commented on Feb 28, 2022

    @mdynnl
    ContributorAuthor

    I'll just put this here also, cause this is related but falls under feature request. https://playground.solidjs.com/?hash=101101936&version=1.3.7

  4. ryansolid commented on Feb 28, 2022

    @ryansolid
    Member

    Hmm. Yeah that's tricky.. mostly that Show doesn't treat the callback without arguments as a callback but instead as passing an accessor as a child. There just isn't a good way to differentiate. In which case it is just passing the function through which isn't memoized or an actual signal itself. This means that in the fragment context it is re-running without guards.. which happens because it's nested as the Show is memoized but the value it returns is just a function that isn't, and in theory this could be true to n-depth.

    The handling is imperfect but also I'd argue this usage is incorrect since your intention isn't to return a non-memoized child and rather have it work like a callback form. Technically the correct solve is to run the children helper perhaps but this may have other implications. Hmm... the conceptual problem is that callback without argument behaves differently. In a sense that the helper is too overloaded. It's possible control flow should be returning children(() =>) instead of createMemo(() =>). That is interesting.

    In anycase this is a longer term consideration. I doubt we change anything here immediately but it is worth considering for future big changes.

  5. ryansolid commented on Mar 30, 2022

    @ryansolid
    Member

    Yeah given this issue will just go stale here. I am going to close it as we aren't going to be taking any action in the near future as this pattern basically is a concession by design and easy to point to as improper use as there shouldn't be an expectation of it working as indicated. This takes more than just wrapping the value sufficiently as the API basically doesn't lend to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions