Skip to content
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

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

Open
0XPW87 opened this issue Jan 16, 2025 · 2 comments
Open

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

0XPW87 opened this issue Jan 16, 2025 · 2 comments
Labels
awaiting submitter needs a reproduction, or clarification

Comments

@0XPW87
Copy link

0XPW87 commented Jan 16, 2025

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

@paoloricciuti
Copy link
Member

It seems to work fine

Please provide an actual reproduction, possibly in the REPL with a non working code. 😄

@paoloricciuti paoloricciuti added the awaiting submitter needs a reproduction, or clarification label Jan 16, 2025
@0XPW87
Copy link
Author

0XPW87 commented Jan 17, 2025

Hey,

thanks for the reply- as mentioned, this was only observed in firefox 128.5, when navigating back a page, AND having disabled network cache, so I presume you won’t see it in the playground with a non network request.

I don’t have my code with me (I can upload it later), but replacing the promise with a call to an endpoint returning that json is basically the entire code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting submitter needs a reproduction, or clarification
Projects
None yet
Development

No branches or pull requests

2 participants