Skip to content

$state array does not update on page back when reassigned #15038

@0XPW87

Description

@0XPW87

Describe the bug

When using the page back browser button, an array declared with $state is not reactive when using reassignment to change its value in firefox

Reproduction

let favourites = $state([])

onMount(() => {
     //this is a network promise in the actual code
     Promise.resolve({"favourites": [1, 2, 3]}).then(res => {


           //-----this causes the state to not update
           favourites = res["favourites"];
           //----


           //===but when using this, it works
           favourites.length = 0;
           for(let a of res["favourites"]){
                 favourites.push(a);
           }
           //====


     })
})

System Info

Observed only in firefox (my version - Mozilla Firefox 128.5.0esr)- not in chromium, AND only when "Disable cache" in network dev tools is turned off

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting submitterneeds a reproduction, or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions