tamagui: Disabled button error with animation

Current Behavior

When button have animation, and we are disabling a button, it throws an error: ERROR Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.

Expected Behavior

Button should correctly apply disabled styles

Tamagui Version

1.116.12

Platform (Web, iOS, Android)

iOS, Android

I don’t know about web

Reproduction

1. Create new StyledButton component:

import { Button, styled } from "tamagui";
const StyledButton = styled(Button, {
  animation: "quick",
});

2. Use this button and change it to disable

export default function IndexScreen() {
  const [isDisabled, setIsDisabled] = useState(false);

  return (
    <>

      <Button onPress={() => setIsDisabled(!isDisabled)}>
        {isDisabled ? "Enable" : "Disable"}
      </Button>

      <StyledButton disabled={isDisabled}>
        State: {isDisabled ? "Disabled" : "Enabled"}
      </StyledButton>
    </>
  );

System Info

System:
    OS: macOS 15.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 896.67 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.18.0 - ~/.nvm/versions/node/v20.18.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.18.0/bin/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v20.18.0/bin/npm
  Browsers:
    Chrome: 130.0.6723.116
    Safari: 18.1
  npmPackages:
    @apollo/client: ^3.11.8 => 3.11.8
    @babel/core: ^7.20.0 => 7.25.9
    @expo/vector-icons: ^14.0.2 => 14.0.4
    @graphql-codegen/cli: ^5.0.3 => 5.0.3
    @graphql-codegen/graphql-modules-preset: ^4.0.10 => 4.0.10
    @graphql-codegen/introspection: ^4.0.3 => 4.0.3
    @graphql-codegen/typescript-react-apollo: ^4.3.2 => 4.3.2
    @graphql-codegen/typescript-resolvers: ^4.3.0 => 4.3.0
    @graphql-eslint/eslint-plugin: ^3.20.1 => 3.20.1
    @hookform/resolvers: ^3.9.0 => 3.9.0
    @react-native-community/datetimepicker: 8.0.1 => 8.0.1
    @react-navigation/native: ^6.0.2 => 6.1.18
    @sentry/react-native: ~5.24.3 => 5.24.3
    @tamagui/babel-plugin: ^1.116.12 => 1.116.12
    @tamagui/config: ^1.116.12 => 1.116.12
    @tamagui/portal: ^1.116.12 => 1.116.12
    @tamagui/toast: ^1.116.12 => 1.116.12
    @tanstack/react-query: ^5.59.16 => 5.59.16
    @types/jest: ^29.5.12 => 29.5.14
    @types/react: ~18.2.45 => 18.2.79
    @types/react-test-renderer: ^18.0.7 => 18.3.0
    axios: ^1.7.7 => 1.7.7
    burnt: ^0.12.2 => 0.12.2
    eslint: ^8.57.0 => 8.57.1
    eslint-config-expo: ^7.1.2 => 7.1.2
    eslint-config-prettier: ^9.1.0 => 9.1.0
    eslint-config-universe: ^13.0.0 => 13.0.0
    eslint-plugin-prettier: ^5.2.1 => 5.2.1
    expo: ~51.0.28 => 51.0.38
    expo-constants: ~16.0.2 => 16.0.2
    expo-dev-client: ~4.0.28 => 4.0.28
    expo-device: ~6.0.2 => 6.0.2
    expo-font: ~12.0.9 => 12.0.10
    expo-linear-gradient: ~13.0.2 => 13.0.2
    expo-linking: ~6.3.1 => 6.3.1
    expo-notifications: ~0.28.19 => 0.28.19
    expo-router: ~3.5.23 => 3.5.23
    expo-secure-store: ~13.0.2 => 13.0.2
    expo-splash-screen: ~0.27.5 => 0.27.6
    expo-status-bar: ~1.12.1 => 1.12.1
    expo-system-ui: ~3.0.7 => 3.0.7
    expo-updates: ~0.25.27 => 0.25.27
    expo-web-browser: ~13.0.3 => 13.0.3
    graphql: ^16.9.0 => 16.9.0
    graphql-codegen-typescript-validation-schema: ^0.16.0 => 0.16.0
    jest: ^29.2.1 => 29.7.0
    jest-expo: ~51.0.3 => 51.0.4
    prettier: ^3.3.3 => 3.3.3
    react: 18.2.0 => 18.2.0
    react-dom: 18.2.0 => 18.2.0
    react-hook-form: ^7.53.1 => 7.53.1
    react-native: 0.74.5 => 0.74.5
    react-native-gesture-handler: ~2.16.1 => 2.16.2
    react-native-reanimated: ~3.10.1 => 3.10.1
    react-native-safe-area-context: 4.10.5 => 4.10.5
    react-native-screens: 3.31.1 => 3.31.1
    react-native-web: ~0.19.10 => 0.19.13
    react-test-renderer: 18.2.0 => 18.2.0
    tamagui: ^1.116.12 => 1.116.12
    typescript: ~5.3.3 => 5.3.3
    yup: ^1.4.0 => 1.4.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 10
  • Comments: 18 (4 by maintainers)

Most upvoted comments

Will check this one soon

I have the same issue on 1.118.1. I noticed that you can work around the issue if you provide a key whose value changes with the disabled state.

For example, modifying the example above:

<StyledButton key={`${isDisabled}`} disabled={isDisabled}>
       State: {isDisabled ? "Disabled" : "Enabled"}
</StyledButton>

Same problem here! disabled={booleanState} shows Too many renders problem.

Same problem here!

@natew I can still replicate this with v1.124.18. My buttons look like:

    const [isInFlight, setIsInFlight] = useState(false);
    return (<YStack>
        <Button
          size="$7"
          width="100%"
          // if I use both disabled and opacity, the bug occurs
          disabled={inFlight}
          opacity={inFlight ? 0.5 : 1}
          onPress={() => {
            setIsInFlight(true);
          }}
        >
          Create a new online game
        </Button>
      </YStack>);

The issue only happens on mobile iOS Safari, not on desktop macOS Safari/Chrome.

Edit: It’s a bit more complicated, in my real code the bug happens even with just the disabled prop.

My dependencies rn:

    "@expo/vector-icons": "^14.0.4",
    "@react-navigation/bottom-tabs": "^7.2.0",
    "@react-navigation/native": "^7.0.14",
    "@tamagui/babel-plugin": "^1.125.0",
    "@tamagui/config": "^1.124.18",
    "@tamagui/lucide-icons": "^1.124.18",
    "@tamagui/metro-plugin": "^1.124.18",
    "@tamagui/toast": "^1.124.18",
    "burnt": "^0.12.2",
    "convex": "^1.19.2",
    "expo": "~52.0.35",
    "expo-blur": "~14.0.3",
    "expo-constants": "~17.0.6",
    "expo-font": "~13.0.3",
    "expo-haptics": "~14.0.1",
    "expo-linking": "~7.0.5",
    "expo-router": "~4.0.17",
    "expo-splash-screen": "~0.29.22",
    "expo-status-bar": "~2.0.1",
    "expo-symbols": "~0.2.2",
    "expo-system-ui": "~4.0.8",
    "expo-web-browser": "~14.0.2",
    "immer": "^10.1.1",
    "react": "18.3.1",
    "react-dom": "18.3.1",
    "react-game-engine": "^1.2.0",
    "react-native": "0.76.7",
    "react-native-canvas": "^0.1.40",
    "react-native-game-engine": "^1.2.0",
    "react-native-gesture-handler": "~2.20.2",
    "react-native-reanimated": "~3.16.7",
    "react-native-safe-area-context": "4.12.0",
    "react-native-screens": "~4.4.0",
    "react-native-web": "~0.19.13",
    "react-native-webview": "13.12.5",
    "tamagui": "^1.124.18",
    "use-debounce": "^10.0.4"

I can replicate the issue at v1.117.1, using the disabled props causes too many rerenders on safari based browsers on macOS Sequoia and iOS 18. Firefox and Chrome browsers on MacOS and iOS are not affected.

image

My component is called BigMainButton, all downstream is tamagui code, i couldn’t find any related useEffects in the Button component

This drove me nuts for 2 hours straight 😆 But the key thing worked for now

@jacobffl Was so tensed on this particular issue cuz around 20% of the UI was already done with tamagui. somehow this worked, You are a life saver.