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.
Actions only support a single parameter, which can be an object if you want to pass multiple things see the docs
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?
@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! 馃檹
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.
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.
OK, makes sense. Thanks for clarifying, @antony and @pngwn!
We agreed to rephrase a bit to clarify that actions can have just one parameter (although the signature is correct), re-opening.
This came up initially in #3923 - That it worked with multiple parameters before 3.13.0 was an accident and never an intended behavior.