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

[Bug]: ViewTransitionContext locations are out of sync with the browser #11555

Open
ivany4 opened this issue May 11, 2024 · 1 comment
Open
Labels

Comments

@ivany4
Copy link

ivany4 commented May 11, 2024

What version of React Router are you using?

6.23.0

Steps to Reproduce

Hi there!

I am using the context, in order to set up clues of navigation direction for specific view transitions, suggested here. It works with regular navigation, but gets quickly confused with browser history back/forward navigation. Pseudo code reproducer:

import { useContext } from 'react';
import { UNSAFE_ViewTransitionContext } from 'react-router-dom';

function useTracking() {
    const ctx = useContext(UNSAFE_ViewTransitionContext);
    if (ctx.isTransitioning === true) {
        console.log(`From ${ctx.currentLocation.pathname} to ${ctx.nextLocation.pathname}`);
    }
}

function PageA() {
     useTracking();
     return <NavLink to="/b" unstable_viewTransition />;
}

function PageB() {
    useTracking();
    return <NavLink to="/a" unstable_viewTransition />;
}

Now, if I start in Page A, go to Page B, and then press browser back button, it will console print twice From /a to /b. However, if at any point on Page B I will navigate to Page A by clicking NavLink, tracking seems to be restored (even when navigating using browser Back/Forward), and it will correctly print current and next locations.

I am testing this in Chromium 123.0.6312.105. Of course, I am not sure whether I am using the right tool for the task, but there's very little information on view transitions at the moment, so it's a guessing game.

Expected Behavior

Current and next location are consistently identified regardless of whether navigation is happening using links or browser history

Actual Behavior

Current and next location are becoming out of sync with the browser history

@ivany4 ivany4 added the bug label May 11, 2024
@ivany4
Copy link
Author

ivany4 commented May 19, 2024

Update: In Google IO '24 they've announced view transition types, that help to achieve what I was trying to achieve with global classes here. More info: https://developer.chrome.com/blog/view-transitions-update-io24#view-transition-types. The hook from my example might not be needed anymore, but this new API will require an API update from react-router.

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

No branches or pull requests

1 participant