react-navigation / react-navigation

Routing and navigation for your React Native apps
https://reactnavigation.org
23.61k stars 5.04k forks source link

Changing CSS variables dynamically causes error #12197

Open jonathanhuang13 opened 1 month ago

jonathanhuang13 commented 1 month ago

Current behavior

I have a CSS selector that changes the CSS variable like so:

@layer base {
  :root {
    --primary: theme('colors.red.500');
  }

  .dark:root {
    --primary: theme('colors.blue.500');
  }
}

When I apply that className like so:

export default function HomeScreen() {
  const [dark, setDark] = useState(false);

  return (
    <View className={dark ? 'dark pt-20' : 'pt-20'}>
      <Text className="bg-primary">Hi</Text>
      <Button title="Toggle dark" onPress={() => setDark(!dark)} />
    </View>
  );
}

I get an error:

Error: Couldn't find a navigation context. Have you wrapped your app with 'NavigationContainer'? See https://reactnavigation.org/docs/getting-started for setup instructions.

This only happens if the CSS variables replace an existing CSS variable. For example, this will work:

@layer base {
  :root {
    --primary: theme('colors.red.500');
  }

  .dark:root {
    --primary2: theme('colors.blue.500'); // 'primary2' does not replace 'primary'
  }
}

Expected behavior

Changing the CSS variable should not break React Navigation

Reproduction

https://github.com/jonathanhuang13/expo-css-variables-issue

Platform

Packages

Environment

package version
@react-navigation/native 6.1.18
react-native 0.74.5
expo 51.0.28
node 20.9
npm 10.1
github-actions[bot] commented 1 month ago

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

jonathanhuang13 commented 1 month ago

Yes, the issue still exists on 6.1.18

github-actions[bot] commented 1 month ago

Hey @jonathanhuang13! Thanks for opening the issue. It seems that the issue doesn't contain a link to a repro.

The best way to get attention to your issue is to provide an easy way for a developer to reproduce the issue.

You can provide a repro using any of the following:

satya164 commented 1 month ago

You need to provide a minimal repro that uses React Navigation directly without any framework.

github-actions[bot] commented 1 day ago

Hello 👋, this issue has been open for more than a month without a repro or any activity. If the issue is still present in the latest version, please provide a repro or leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution or workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix it.