What kind of issue is this?
Link to repro
https://playground.react.dev/#N4Igzg9grgTgxgUxALhASwLYAcIwC4AEwBUYCAwgIYA21ARpXANYA0JZAogGZcJx5tSCAMp5KeBAQC+BLjAgYCAchgJGeJQG4AOgDs9erlF380EXQQDmCPADUaUBAAoAlET0ECqvLAtK8MI5aelIGuggAHjj4ssam5gQAkhiU1gAyaHQwlDAAngAKaMwIMK7u+hYEcOZghHQQENSiMGi6lgQAvFY29tSOrjqV1bq1BADamKkIYGxkeMlTYAC6newiYhJOSkoug57Do2P1jWq6ouIIszYAQg3Up+cSK11CjwgAPMf3lLoAfE4AKWEAHkAHIAOiwOTITi+zValhcuzCHiqNUIZBycAAFqshFRaAxmE4yh1fuVPJ45gtrGAtjs9tI2GMlsiKp4hNxePwSW4yRTKZj4NiBqipMyhTjWYNUd5fARdFBaINQroQCwQMMuGhLCgQMBUQB6Q3VbBoajiMy6ACyEAAJghkARtCAaNQXSF1eBsRAAO6JXQSGC6GhgFBcUMIKRAA
Repro steps
If the useCallback does not include the state setter setImages in its dependency array, the compiler produces the error:
Compilation Skipped: Existing memoization could not be preserved
React Compiler has skipped optimizing this component because the existing manual
memoization could not be preserved. The inferred dependencies did not match the
manually specified dependencies, which could cause the value to change more or less
frequently than expected. The inferred dependency was `setImages`, but the source
dependencies were []. Inferred dependency not present in source.
Adding setImages to the dependency array resolves the compiler error, but according to rules of React, state setter functions should not be required in the dependency array.
Also, slightly tweaking the surrounding (apparently unrelated) code also makes the error disappear, which seems to indicate this might be a bug.
For example,
How often does this bug happen?
Every time
What version of React are you using?
19.2.5
What version of React Compiler are you using?
babel-plugin-react-compiler @ 1.0.0
eslint-plugin-react-hooks @ 7.1.1
What kind of issue is this?
Link to repro
https://playground.react.dev/#N4Igzg9grgTgxgUxALhASwLYAcIwC4AEwBUYCAwgIYA21ARpXANYA0JZAogGZcJx5tSCAMp5KeBAQC+BLjAgYCAchgJGeJQG4AOgDs9erlF380EXQQDmCPADUaUBAAoAlET0ECqvLAtK8MI5aelIGuggAHjj4ssam5gQAkhiU1gAyaHQwlDAAngAKaMwIMK7u+hYEcOZghHQQENSiMGi6lgQAvFY29tSOrjqV1bq1BADamKkIYGxkeMlTYAC6newiYhJOSkoug57Do2P1jWq6ouIIszYAQg3Up+cSK11CjwgAPMf3lLoAfE4AKWEAHkAHIAOiwOTITi+zValhcuzCHiqNUIZBycAAFqshFRaAxmE4yh1fuVPJ45gtrGAtjs9tI2GMlsiKp4hNxePwSW4yRTKZj4NiBqipMyhTjWYNUd5fARdFBaINQroQCwQMMuGhLCgQMBUQB6Q3VbBoajiMy6ACyEAAJghkARtCAaNQXSF1eBsRAAO6JXQSGC6GhgFBcUMIKRAA
Repro steps
If the useCallback does not include the state setter
setImagesin its dependency array, the compiler produces the error:Adding
setImagesto the dependency array resolves the compiler error, but according to rules of React, state setter functions should not be required in the dependency array.Also, slightly tweaking the surrounding (apparently unrelated) code also makes the error disappear, which seems to indicate this might be a bug.
For example,
How often does this bug happen?
Every time
What version of React are you using?
19.2.5
What version of React Compiler are you using?
babel-plugin-react-compiler @ 1.0.0
eslint-plugin-react-hooks @ 7.1.1