svelte icon indicating copy to clipboard operation
svelte copied to clipboard

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

Open MrWaip opened this issue 1 year ago • 7 comments

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

[email protected]

Severity

annoyance

MrWaip avatar Oct 23 '24 08:10 MrWaip

This is also reproduced with typescript enams

MrWaip avatar Oct 23 '24 08:10 MrWaip

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

brunnerh avatar Oct 23 '24 08:10 brunnerh

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

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

MrWaip avatar Oct 23 '24 09:10 MrWaip

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.

brunnerh avatar Oct 23 '24 09:10 brunnerh

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

paoloricciuti avatar Oct 23 '24 20:10 paoloricciuti

Tricky rule

MrWaip avatar Oct 23 '24 22:10 MrWaip

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

benmccann avatar Nov 01 '24 17:11 benmccann