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

Fix back navigation after POST form submission #1014

Merged
merged 1 commit into from Sep 28, 2023
Merged

Conversation

afcapel
Copy link
Collaborator

@afcapel afcapel commented Sep 27, 2023

This commit fixes a bug where navigating back after submitting a POST form would not show the previous page. The bug was introduced in #949. The new cache API is async since it needs to access CacheStorage which is async. In that PR, getCachedSnapshot was changed to be async, but hasCachedSnapshot was not changed. This meant that getCachedSnapshot would always return a promise, which is truthy, and so hasCachedSnapshot which just checked that the return value was not null would always return true.

The bug would show up when you tried to navigate back to a page after a post form submission. The form submission would clear the cache, but the restoration visit would think it had a cached snapshot and so would not issue a request. This meant that the page would not be restored and nothing would happen.

There's a new test in navigation_tests.js that reproduces this bug.

The fix is to make hasCachedSnapshot async and await it in the places where it is used.

This commit fixes a bug where navigating back after submitting a POST
form would not show the previous page. The bug was introduced in
#949. The new cache API is async
since it needs to access CacheStorage which is async. In that PR,
getCachedSnapshot was changed to be async, but hasCachedSnapshot was not
changed. This meant that getCachedSnapshot would always return a promise,
which is truthy, and so hasCachedSnapshot which just checked that the
return value was not null would always return true.

The bug would show up when you tried to navigate back to a page after
a post form submission. The form submission would clear the cache, but the
restoration visit would think it had a cached snapshot and so would not
issue a request. This meant that the page would not be restored and nothing
would happen.

There's a new test in navigation_tests.js that reproduces this bug.

The fix is to make hasCachedSnapshot async and await it in the places
where it is used.
Copy link
Collaborator

@kevinmcconnell kevinmcconnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Nice catch 👏

@afcapel afcapel merged commit c207f5b into main Sep 28, 2023
2 checks passed
@afcapel afcapel deleted the back-navigation branch September 28, 2023 10:21
@jorgemanrubia jorgemanrubia mentioned this pull request Oct 10, 2023
2 tasks
afcapel added a commit that referenced this pull request Nov 13, 2023
@afcapel afcapel mentioned this pull request Nov 13, 2023
afcapel added a commit that referenced this pull request Nov 13, 2023
* Revert "Move cache snapshot loading to Visit#start() (#1056)"

This reverts commit e07639f.

* Revert "Fix back navigation after POST form submission (#1014)"

This reverts commit c207f5b.

* Revert "Add disk cache store (#949)"

This reverts commit f86a376.

* Remove redudant test prefix

* Bring back test

Orginally added by @jayohms in

60cfbee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants