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

Redirect not work in SSR mode in 2.9 version using React 18 #293

Open
Mati365 opened this issue Mar 2, 2023 · 2 comments
Open

Redirect not work in SSR mode in 2.9 version using React 18 #293

Mati365 opened this issue Mar 2, 2023 · 2 comments
Labels
unclear Probably needs more context, or can't be reproduced

Comments

@Mati365
Copy link

Mati365 commented Mar 2, 2023

This code:

<Redirect to='/login' />

is not triggering redirect in SSR (on client side it is working correctly). Probably because used for example here:

wouter/index.js

Line 188 in efda2ab

useIsomorphicLayoutEffect(() => {

useIsomorphicLayoutEffect hook is not being called in SSR mode (using React 18.x). navigation seems not to be working too.

Workaround:

export const Redirect = ({ to }: RedirectProps) => {
  const [, navigate] = useLocation();
  const router = useRouter();

  if (isSSR()) {
    (router.hook as any).history.push(concatUrls(router.base, to));
  }

  useAfterMount(() => {
    navigate(to);
  });

  return null;
};
@Mati365 Mati365 changed the title Redirect not work in SSR mode in 2.9 version Redirect not work in SSR mode in 2.9 version using React 18 Mar 2, 2023
@cbbfcd
Copy link
Contributor

cbbfcd commented Mar 6, 2023

the problem may be here:

useSyncExternalStore(subscribeToLocationUpdates, fn);

@Mati365
Copy link
Author

Mati365 commented Jun 26, 2023

it is still broken in 2.11

@molefrog molefrog added the unclear Probably needs more context, or can't be reproduced label Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unclear Probably needs more context, or can't be reproduced
Projects
None yet
Development

No branches or pull requests

3 participants