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

change nav type to redirect when doing live navigation #3538

Closed
wants to merge 1 commit into from

Conversation

SteffenDE
Copy link
Collaborator

Fixes #3536.

Browser history API strikes back (again). Because live navigation shares the id of the view between live navigations, the following scenario could happen:

  1. User visits page 1 (initial nav)
  2. User patches the page
  3. User visits page 2 (live nav)
  4. User patches the page
  5. User uses browser back button (state from 3 -> live nav)
  6. User uses browser back button (state from 2 -> PATCH)

In step 6, the user is still on page 2, but LiveView would try to patch the page instead of performing a live navigation. This is only a problem if the two pages use the same underlying LiveView module, otherwise the patch request would fallback to a navigation.

This commit "fixes" this by modifying the current history entry at step 2 to redirect before pushing the new state. This way, LiveView does a live navigation when popping the state in step 6.

The underlying problem is that we cannot differentiate a forward from a backward navigation when handling a popstate. If we could, we'd be able to separately store the backwards and forwards navigation type. The current approach will also do a live navigation when navigating forward again, therefore if a user went back in history to step 1 and pressed forward, we now do a live navigation instead of a patch, therefore potentially losing state.

See also #3513 (comment).

Fixes #3536.

Browser history API strikes back (again). Because live navigation shares
the id of the view between live navigations, the following scenario could
happen:

1. User visits page 1 (initial nav)
2. User patches the page
3. User visits page 2 (live nav)
4. User patches the page
5. User uses browser back button (state from 3 -> live nav)
6. User uses browser back button (state from 2 -> PATCH)

In step 6, the user is still on page 2, but LiveView would try to patch
the page instead of performing a live navigation. This is only a problem
if the two pages use the same underlying LiveView module, otherwise the
patch request would fallback to a navigation.

This commit "fixes" this by modifying the current history entry at
step 2 to `redirect` before pushing the new state. This way, LiveView
does a live navigation when popping the state in step 6.

The underlying problem is that we cannot differentiate a forward from a
backward navigation when handling a popstate. If we could, we'd be able
to separately store the backwards and forwards navigation type. The
current approach will also do a live navigation when navigating forward
again, therefore if a user went back in history to step 1 and pressed
forward, we now do a live navigation instead of a patch, therefore
potentially losing state.

See also #3513 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Live Navigation with mix of patch/navigate doesn't update properly with browser/history back button
1 participant