Skip to content

fix: dependencies array changes size between renders#1229

Merged
kirillzyusko merged 4 commits intomainfrom
fix/deps-array-size-changes
Dec 3, 2025
Merged

fix: dependencies array changes size between renders#1229
kirillzyusko merged 4 commits intomainfrom
fix/deps-array-size-changes

Conversation

@kirillzyusko
Copy link
Copy Markdown
Owner

@kirillzyusko kirillzyusko commented Dec 2, 2025

📜 Description

Fixed The final argument passed to %s changed size between renders. The order and size of this array must remain constant. warning.

💡 Motivation and Context

This warning happens inside useSmoothKeyboardHandler and started to happen after #1209 The main difference from these changes is that we started to use useHandler/useEvent hooks, while in the past we simply used direct worklet registration.

Turns out useAnimatedReaction modifies array of dependencies:

if (dependencies === undefined) {
    dependencies = [
      ...Object.values(prepare.__closure ?? {}),
      ...Object.values(react.__closure ?? {}),
      prepare.__workletHash,
      react.__workletHash,
    ];
  } else {
    dependencies.push(prepare.__workletHash, react.__workletHash);
  }

Then useHandler (used in useKeyboardHandler) uses buildDependencies which also modifies the array of dependencies:

dependencies.push(buildWorkletsHash(handlersList));

So if we use deps like:

const useMyCustomHook = (deps) => {
  useAnimatedReaction(() => {}, deps);
  
  useKeyboardHandler({}, deps);
}

Then we'll get this warning because we mutate deps two times.

To fix this issue I decided to make a shallow copy of deps for useAnimatedReaction hook. It fixes the problem 🤞

Closes #1228

📢 Changelog

JS

  • create shallow array copy for useAnimatedReaction in useSmoothKeyboardHandler;

🤔 How Has This Been Tested?

Tested manually on iPhone 16 Pro.

📸 Screenshots (if appropriate):

Before After
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-12-02.at.12.50.41.mov
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-12-02.at.12.49.17.mov

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@kirillzyusko kirillzyusko self-assigned this Dec 2, 2025
@kirillzyusko kirillzyusko added 🐛 bug Something isn't working KeyboardAwareScrollView 📜 Anything related to KeyboardAwareScrollView component labels Dec 2, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 2, 2025

📊 Package size report

Current size Target Size Difference
230170 bytes 230136 bytes 34 bytes 📈

@kirillzyusko kirillzyusko force-pushed the fix/deps-array-size-changes branch from f56d900 to f49f5b6 Compare December 2, 2025 14:48
@kirillzyusko kirillzyusko marked this pull request as ready for review December 3, 2025 09:10
@kirillzyusko kirillzyusko merged commit 70784fd into main Dec 3, 2025
14 checks passed
@kirillzyusko kirillzyusko deleted the fix/deps-array-size-changes branch December 3, 2025 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working KeyboardAwareScrollView 📜 Anything related to KeyboardAwareScrollView component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[1.20.0] useEffect dependencies array changes size between renders in KeyboardAwareScrollView

1 participant