sveltejs / svelte

web development for the rest of us
https://svelte.dev
MIT License
80.28k stars 4.27k forks source link

Warning: Properties of objects and arrays are not reactive unless in runes mode #13811

Open MrWaip opened 1 month ago

MrWaip commented 1 month ago

Describe the bug

Hi, I just updated svelte to version 5, and I get this warning

Properties of objects and arrays are not reactive unless in runes mode. Changes to this property will not cause the reactive statement to update 

There is obviously some bug in the analyzer. I do not mutate the object, but read its property

image

Reproduction

https://svelte.dev/playground/d38ff4e52c9c4b1cb7b5314a662e479a?version=5.0.5

Logs

No response

System Info

svelte@5.0.5

Severity

annoyance

MrWaip commented 1 month ago

This is also reproduced with typescript enams

brunnerh commented 1 month ago

There is obviously some bug in the analyzer. I do not mutate the object, but read its property

The warning is telling you that if Marker.A is changed elsewhere, this reactive statement will not trigger in legacy mode. The warning is correct in principle, but if Marker.A is immutable, this is a false positive.

You can ignore the warning using

// svelte-ignore reactive_declaration_non_reactive_property
MrWaip commented 1 month ago

In my case Marker is immutable. It's enum.

I don't really like the idea of monkey patching everywhere with comments)

brunnerh commented 1 month ago

The problem is probably that components are analyzed in isolation, possibly without type information from the outside; at least that used to be the case previously.

paoloricciuti commented 1 month ago

The problem is probably that components are analyzed in isolation, possibly without type information from the outside; at least that used to be the case previously.

Yup this is correct

MrWaip commented 1 month ago

Tricky rule

benmccann commented 1 month ago

here's a Svelte 5 upgrade PR that has lots of ignores related to this warning if you want to see some examples: https://github.com/immich-app/immich/pull/13738