The issue involves understanding and fixing inconsistent memoization strategies in the React Compiler.
The React Compiler generates different memoization strategies for objects with method shorthand versus function properties, leading to inconsistent behavior. The task involves identifying the root cause and ensuring consistent memoization. This requires understanding compiler internals and memoization logic.
React Compiler generates different memoization strategies depending on whether functions in a returned object are defined using method shorthand or function/arrow properties.
In some cases, the compiler memoizes individual functions and reconstructs the object, while in others it memoizes the entire object directly.
export function useBug() {
const { setNodes, setEdges } = useAgentActions();
return {
memoized,
test1() {
setNodes(resolveCollisions);
},
test2() {
setEdges(resolveCollisions);
},
test3(_, node) {
console.log(resolveCollisions);
},
};
}
import { c as _c } from "react/compiler-runtime";
export function useBug() {
const $ = _c(3);
const { setNodes, setEdges } = useAgentActions();
let t0;
if ($[0] !== setEdges || $[1] !== setNodes) {
t0 = {
memoized,
test1() { // recreated when cached object is rebuilt
setNodes(resolveCollisions);
},
test2() { // recreated when cached object is rebuilt
setEdges(resolveC
Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!