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

Array access not supported in the use or transition directives #11467

Closed
fcrozatier opened this issue May 4, 2024 · 5 comments
Closed

Array access not supported in the use or transition directives #11467

fcrozatier opened this issue May 4, 2024 · 5 comments

Comments

@fcrozatier
Copy link
Contributor

fcrozatier commented May 4, 2024

Describe the bug

This syntax

{#each assembly.speakers as speaker, i}
	<button use:assembly.speakers[i].action>speaker {i}</button>
{/each}

gets compiled down to

$.action(button, ($$node) => assembly["speakers[i]"].action($$node));

so the array access doesn't work.

But all the other variations do work so it's a bit confusing / seems like a bug.

Same thing for transitions

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE5WS3W6DMAyFX8XLJg2kQu9bQNsz7LLpRUrdNRokKDarKsS7TwFCW3XazwWI-Dg-n206cdAVklhtOmFUjWIlXptGLASfG3-gT6wYxUKQbV3pIxmVTjdcSCNZ1411DN1B7bGHg7M1yOnKkp0ypFlbI8XaJ_unrBQRvDWoPtBBN4RZlT4LcohiyIsQlVxaQ7bCtLLvkRRHLUU8Sr0048fFA3LwEIPRJI9er0RY76ozhLo0mhPk8ESsGKPNNl5PnsO7dKgYA6THyosbKAaaRYOn0E8UhwqS-agpDVZp09Ixmk5xSHHIrTOh1KWzmX9wUoF_tArtRCNyUNMb5kHMlpdFmewhSWBvkcwzw8m6D5AmSQppukdU5XF2mZFBUSBbgB6wsl3LbA20hKu7_I3eptMetfleviyrCOPrdJ8tx7KeZelZ-sDrMelfhN3LNLPwQ_2AeXPh5j_6Bf5-FnPbf-9wmP20lv_3ee0-SVfDD5G_00CSFGIharvXB417sWLXYr_tvwCr6_BOHQQAAA==

Logs

No response

System Info

preview

Severity

annoyance

@fcrozatier fcrozatier changed the title Array access not supported for the use directive Array access not supported in the use directive May 4, 2024
@fcrozatier fcrozatier changed the title Array access not supported in the use directive Array access not supported in the use or transition directive May 4, 2024
@fcrozatier fcrozatier changed the title Array access not supported in the use or transition directive Array access not supported in the use or transition directives May 4, 2024
@Rich-Harris
Copy link
Member

This isn't a bug, exactly, it's just a limitation of the syntax. Ultimately we don't want to invest more in actions (we have ideas for a better set of primitives) beyond matching what works in Svelte 4, so I'm going to close this — the recommended solution is to use the {@const ...} workaround.

@Rich-Harris Rich-Harris closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2024
@fcrozatier
Copy link
Contributor Author

Ok makes sense. Just out of curiosity what would be the better primitives replacing actions?

@Rich-Harris
Copy link
Member

Too soon to say exactly what they'd look like, but essentially we need a) better programmatic control over element lifecycle (to enable better coordination between different elements, to control when elements can be removed from the DOM, etc) and a syntax that doesn't force you to jump through hoops. It'll be a focus of a future release, post-5.0

@fcrozatier
Copy link
Contributor Author

Sounds great. Hopefully this could be a spreadable syntax unlike use:, making it easier for libs to offer spreadable objects without worrying with overriding user actions unlike when spreading event attributes

@Rich-Harris
Copy link
Member

Yep, making this stuff spreadable is very much part of the plan

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.

2 participants