Skip to content

Action's parameters are not being passed correctly #5173

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

Closed
yuliankarapetkov opened this issue Jul 21, 2020 · 8 comments · Fixed by #5178
Closed

Action's parameters are not being passed correctly #5173

yuliankarapetkov opened this issue Jul 21, 2020 · 8 comments · Fixed by #5178

Comments

@yuliankarapetkov
Copy link

Describe the bug
When you pass a list of parameters to an action, only the last parameter in the list is being received by the function. What's more, the parameter is being "moved" to the first position.

<script>	
	function test (node, el1, el2, el3) {
		console.log(el1, el2, el3) // logs `third undefined undefined`, instead of `first second third`
	}
</script>

<h1 use:test={'first', 'second', 'third'}>Hello!</h1>

This used to work in 3.12.1 but it doesn't work in 3.24.0

To Reproduce
Open the this REPL and see the logs. Compare the logs with that one.

Expected behavior
Parameters should be passed correctly.

@antony
Copy link
Member

antony commented Jul 21, 2020

Actions only support a single parameter, which can be an object if you want to pass multiple things see the docs

@antony antony closed this as completed Jul 21, 2020
@antony antony added the invalid label Jul 21, 2020
@yuliankarapetkov
Copy link
Author

I see, it used to work differently in 3.12.1 and then maybe in this case the log should show first, not third, right?

@jhwheeler
Copy link

@yuliankarapetkov I agree it should show first instead of third.

@antony I would classify this as a breaking change, as we had code using 3.12.1 w/ multiple params that no longer works. And in the changelog for 3.13.0 (when this change seemed to have been made), there isn't anything about this change. It would be helpful to have a small note about this in the changelog. Thanks! 🙏

@antony
Copy link
Member

antony commented Jul 21, 2020

If something is undocumented and unintentional, it's subject to change without us noticing, so it's difficult to make a changelog for something which wasn't supported, and for something which we weren't aware of the current behaviour, if that makes sense?

The behaviour is now according to the docs, and documented accordingly, any former behaviour was simply as-was.

The same applies for the parameter ordering, we only support passing a single parameter, so therefore that behaviour is documented, tested, and works as described - if you call methods with invalid signatures, then invalid behaviour may well occur.

@pngwn
Copy link
Member

pngwn commented Jul 21, 2020

Multiple parameters working was a bug and we have fixed that now.

@yuliankarapetkov

I see, it used to work differently in 3.12.1 and then maybe in this case the log should show first, not third, right?

No, the current behaviour is expected. The argument you provide to an action is an expression that is passed as the second parameter to the action function:

<div use:fn={1, 2, 3} />

Is actually doing this:

fn(
  node, 
  (1, 2, 3)
)

Evaluating the expression (1, 2, 3) will return 3.

@jhwheeler
Copy link

OK, makes sense. Thanks for clarifying, @antony and @pngwn!

@mindrones
Copy link
Member

We agreed to rephrase a bit to clarify that actions can have just one parameter (although the signature is correct), re-opening.

@Conduitry
Copy link
Member

This came up initially in #3923 - That it worked with multiple parameters before 3.13.0 was an accident and never an intended behavior.

Truffula pushed a commit to Truffula/svelte that referenced this issue Aug 3, 2020
taylorzane pushed a commit to taylorzane/svelte that referenced this issue Dec 17, 2020
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

Successfully merging a pull request may close this issue.

6 participants