Skip to content
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

Svelte v4 code running with Svelte v5: Function passed as slot variable is no longer a function when consumed #12213

Open
webJose opened this issue Jun 27, 2024 · 5 comments

Comments

@webJose
Copy link

webJose commented Jun 27, 2024

Describe the bug

I the library I'm working on, I have a not-so-simple arrangement of components that together form a menu toolbar. The base component provides a named slot with a variable named setCurrentNode that, when run (because it is a function), performs the menu navigation. The function really teakes two parameters, but the second parameter is pre-filled by the base component, so the slot looks like this:

...
<slot name="node" setCurrentNode={(n) => setCurrentNode(n, parent)}>
   ...
</slot>
...

This works as expected in Svelte v4. In Svelte v5-next.166, however, the function is no longer a function. The consumer component, when doing let:setCurrentNode does not receive a function in the setCurrentNode variable and instead receives an object:

image

The word "object" in the screenshot is the result of typeof setCurrentNode.

If you notice, there's an fn property in the object that looks like a function. I tested by modifying the code from setCurrentNode(node) to setCurrentNode.fn(node) and this makes the error go away (I did not mention, but the error I get is setCurrentNode is not a function). However, while the error is gone, the logic of setCurrentNode does not seem to be happening.

Reproduction

This is private IP, and I tried to reproduce this, but it seems to be a non-trivial task to do so. If really important, I'll try again, but maybe you Svelte members recognize this object I'm showing in the screenshot and perhaps that's enough to locate the problem? Do let me know, as I'm very willing to help with whatever I can.

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (8) x64 Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
    Memory: 16.17 GB / 39.73 GB
  Binaries:
    Node: 20.13.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.5.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (126.0.2592.56)
    Internet Explorer: 11.0.22621.3527

Severity

blocking all usage of svelte

@webJose
Copy link
Author

webJose commented Jun 27, 2024

I have discovered that setCurrentNode.fn() returns the slot variable contents (what is expected to get directly in setCurrentNode). So I suppose some internal structure is being leaked here, for some reason unknown to me.

@webJose
Copy link
Author

webJose commented Jun 27, 2024

I logged the other slot variables coming from the base component's slot:

image

I guess it is no surprise, but they are all the same "proxy" object. To obtain the slot variable's correct value, the .fn property must be evaluated.

@webJose
Copy link
Author

webJose commented Jun 27, 2024

So, after the investigation, the menu toolbar component can go back to working state by adding .fn() to every slot variable being used:

        on:click={(ev) => {
            if (hasNodes.fn()) {
                (setCurrentNode.fn())(node.fn());
            }
        }}

@paoloricciuti
Copy link
Member

Can you provide a minimal reproduction in the repl?

@webJose
Copy link
Author

webJose commented Jun 30, 2024

Hello. I've tried to reproduce in the REPL but so far I've been unable to. I'll try with Sveltekit.

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

No branches or pull requests

2 participants