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

[router] Fix false positive redirect deprecation since version 2.0.1 when using Screen #23932

Conversation

sync
Copy link
Contributor

@sync sync commented Aug 12, 2023

Why

WARN The redirect prop on is deprecated and will be removed. Please use router.redirect, fixes expo/router#834

I think issue is here perhaps https://github.com/expo/router/blob/f69e31c84a83ceb6d678dfb8aeed708974d301a8/packages/expo-router/src/views/Screen.tsx#L49

if you look at the code, if you do this for example:

<Stack.Screen
       options={{
         title: params.name,
       }}
     />

Then deprecated prop would end up being undefined because redirect would not be set

    useDeprecated(
      "The `redirect` prop on <Screen /> is deprecated and will be removed. Please use `router.redirect` instead",
      redirect
    );

Then looking at useDepecated code here:

export function useDeprecated(
  message: string,
  guard: unknown = true,
  key = message
) {
  return useWarnOnce(key, guard, `Expo Router: ${message}`);
}

the guard would end up being set to true because of the default value guard: unknown = true

How

Avoid sending an undefined redirect prop to the guard

Test Plan

Run updated code and make sure warning is gone

Checklist

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Aug 12, 2023
@sync sync force-pushed the expo-router-screen-redirect-deprecation-false-positive branch 3 times, most recently from abf4891 to 3e8a515 Compare August 12, 2023 08:32
@sync sync force-pushed the expo-router-screen-redirect-deprecation-false-positive branch from 3e8a515 to 8999224 Compare August 12, 2023 08:33
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Aug 12, 2023
Copy link
Contributor

@hyochan hyochan left a comment

Choose a reason for hiding this comment

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

Confirm this resolves problem in my environment 👍

Co-authored-by: Lucas Caton <lucascaton@gmail.com>
@EvanBacon EvanBacon merged commit 7251daf into expo:main Aug 30, 2023
7 checks passed
@sync sync deleted the expo-router-screen-redirect-deprecation-false-positive branch August 30, 2023 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: passed checks ExpoBot has nothing to complain about
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WARN The redirect prop on <Screen /> is deprecated and will be removed. Please use router.redirect
5 participants