You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After checking why Attachments weren't working for my components, I found out that "for in" loops don't iterate over Symbols, and if they were used to process and return a new object of props from the restProps, there is a chance that Attachments would be lost in the process. As someone who doesn't have much experience with Symbols, it bugged me a little bit, and I was hoping there could be at least a warning in the docs for this issue.
Reproduction
Let's say someone wants to filter the restProps using a "for in" loop.
In the code above, the user accidentally removed the Attachments or any other property with a key of Symbol from their processedProps.
Of course, this could be fixed if you were to initially spread the original restProps inside the processedProps like so.
constprocessedProps: Record<any,any>={ ...props};
But when you update your Svelte version and then your Attachments don't work, it could be hard at first to know why this is happening, especially in a large code base, since it's silent with no error as well.
Attachments have symbols as key
Properties that have symbols as key are not enumerable
For in and Object.keys only return enumerable properties
You can use Reflect.ownKeys to get all properties, including non-enumerable ones
Maybe the team could make attachments be declared as enumerable, but I can't think of a real case where that would be useful
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
After checking why Attachments weren't working for my components, I found out that "for in" loops don't iterate over Symbols, and if they were used to process and return a new object of props from the restProps, there is a chance that Attachments would be lost in the process. As someone who doesn't have much experience with Symbols, it bugged me a little bit, and I was hoping there could be at least a warning in the docs for this issue.
Reproduction
Let's say someone wants to filter the restProps using a "for in" loop.
In the code above, the user accidentally removed the Attachments or any other property with a key of Symbol from their processedProps.
Of course, this could be fixed if you were to initially spread the original restProps inside the processedProps like so.
But when you update your Svelte version and then your Attachments don't work, it could be hard at first to know why this is happening, especially in a large code base, since it's silent with no error as well.
Logs
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: