I’m working on a Hotwire Native iOS app. I have a page that links to a second page. On the second page, I can perform actions that would affect the contents of the first page. The problem is that when I do that, the “back” action in the top right takes me back to a stale/cached copy of the first page. Is there a way to force a page reload when I’ve changed the contents of the first page, or some other way to handle this better? Thanks!
Your backend controller should respond to the POST requests with a redirect to /refresh_historical_location
.
class FooController
def create
refresh_or_redirect_to some_path, status: :see_other
end
end
This should bust the cache and pressing the back button should cause the webview to reload.
Let me know if it works!
If the second page submits a form at all the cache will bust. Any standard HTTP POST will trigger it.
Hmm, it was submitting a form though (albeit via js), that’s strange. Well, luckily it happens that we reworked it into one page so the issue doesn’t appear.
Yeah, the framework won’t know about any requests made via JavaScript, It has to come from a boring ol’ HTML <form>
that does a non-GET request.
Hmm. To be clear, I’m calling form.requestSubmit on a regular form. So it’s not making the request via js, just triggering the submit that way. But idk, it’s not a problem for me anymore.
Hey @joemasilotti! Can the behavior to bust cache on POST be disabled somehow? I see the intent but I have a scenario where I’m submitting a form 3 or 4 levels deep in the navigation stack, but each previous page upon hitting Back (all the way back to my root view controller) is forced into the loading spinner and loses state.
I would much rather be responsible for what UI needs to update after form submit than to have re-establish state (scroll offsets, etc) for every other page in my nav stack (in my case, only the previous page is affected by the form submit, which the refresh_or_redirect_to route handles beautifully.
On that note, is there anything else that could bust the cache besides this? For example, say I nav’d 100 pages deep on the stack. Does the cache eventually start FIFO’ing / invalidating older stuff?
Thanks!