inertia icon indicating copy to clipboard operation
inertia copied to clipboard

[2.x] Prefetch causes stale data to be shown after post

Open nick-potts opened this issue 1 year ago • 4 comments

Versions:

  • @inertiajs/core version: 2.0.0-beta.1
  • @inertiajs/react version: 2.0.0-beta.1

Describe the problem:

After submitting a post request that changes the current page's data, the previous prefetch value will still be used and the user will be shown stale data.

Steps to reproduce:

Set a page to be prefetched: "/settings" Visit "/" Visit "/settings" router.post('/settings/update') - this returns data that modifies the settings page data Visit "/" Visit "/settings" - here you'll get the data from the prefetch, not the merged props from the post.

nick-potts avatar Oct 11 '24 10:10 nick-potts

This should be fixed by #2023. Please test it once beta 2 is out 😉

pedroborges avatar Oct 13 '24 10:10 pedroborges

@pedroborges @reinink Any chance this could get released? I'm experiencing quite a lot of issues and I'm not sure if this is solved by #2023 since the tests there only reference deferred props. But I'm also hesitant to report an issue if it's potentially already fixed.

RobertBoes avatar Oct 14 '24 10:10 RobertBoes

Sadly not fixed by beta 2 @pedroborges

https://imgur.com/a/tUAzjgH

nick-potts avatar Oct 18 '24 22:10 nick-potts

Yes, hopefully prefetch will get some love. Just upgraded to beta 2 and still getting those

Uncaught (in promise) DataCloneError: Failed to execute 'replaceState' on 'History': #<Object> could not be cloned. 
From history.ts:101

Cacamoto avatar Oct 28 '24 22:10 Cacamoto

@nick-potts we don't automatically flush the page prefetch after something like a posted form, but you can do it manually on success by passing the same options to router.flush() as you passed to router.prefetch. Does this help you solve this issue?

joetannenbaum avatar Nov 21 '24 18:11 joetannenbaum

That does work. I'm struggling to get it to prefetch the page again afterwards, but I think that's skill issues.

nick-potts avatar Nov 21 '24 23:11 nick-potts

has this issue been resolved now?

lovlyx avatar Dec 13 '24 22:12 lovlyx

Not really, you can very easily end up with stale data in the cache. its mainly up the the developer to try manage it here.

nick-potts avatar Dec 14 '24 05:12 nick-potts

I'm closing this as it's not a bug but something you have to manage yourself, as described above.

pascalbaljet avatar Jul 04 '25 10:07 pascalbaljet