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
Svelte5: reactive Set constructor not working correctly #11222
Comments
This is just how things are logged. it will probably just need to upgrade the toString method too. However since this is blocking an upgrade for you go ahead and use it because the values are there :) EDIT: apparently the |
see this repl as well. As the docs mention, they should behave exactly the same, except this one is reactive. So I still beleive this is not intented. <script>
import {Set} from "svelte/reactivity";
const data = ["1", "2", "3", "4"];
const nativeSet = new window.Set(data);
const reactiveSet = new Set(data);
// 4 elements get logged cause 4 elements in here
nativeSet.forEach((a)=>console.log("n",a));
// nothing gets logged cause nothing in here
reactiveSet.forEach((a)=>console.log("r", a)); // expected to log "r 1 ... 4"
// or if the console.log is not correct as @paoloricciuti says we can test it
reactiveSet.forEach((a)=>console.log("something")); // expected to log "something" 4 times
</script> I've commented what I expect from the console logs, don't you agree they are logical? (this the code from the REPL I've linked) |
This is caused by #11200. The following are broken, I believe: |
As @harrisi was saying this is a different problem from what you showcased in your first repl. I'll see if I can find a fix tomorrow (I don't know if I'll have time tho so if someone else wants to work on this go ahead) |
The fix is to revert #11200 or implement all the methods that are currently implemented by calling Or, don't extend |
Yeah i also commented on the PR. Personally i would revert #11200 ...you could replicate those methods but then there's more work to maintain those classes for a small memory gain. |
It's not only more work, it's not forward-compatible. |
@harrisi what about wrapping the native |
You would still need to call those methods on an actual set instance or JS will throw. |
and also, should it be forward compatible? What if standard adds a new method that mutates the original set in someway, it shouldn't be available in |
The current implementation would still let you call whatever new This discussion is pretty spread out across different places, and really isn't specific to this issue, though. |
But what if the "new methods" added to
I don't know which one is better. |
See #11287 for a potential solution |
Describe the bug
This reproduction sums it up basically. Calling the
Set
constructor from an array doesn't work. If it helps, it does work with production builds.Reproduction
1- goto this REPL.
2- see the logs
Logs
System Info
svelte REPL on "Svelte v5.0.0-next.107"
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: