Skip to content

Conversation

poteto
Copy link
Member

@poteto poteto commented Jun 11, 2025

This bug was reported via our wg and appears to only affect values created as a ref.

Currently, postfix operators used in a callback gets compiled to:

modalId.current = modalId.current + 1; // 1
const id = modalId.current; // 1
return id;

which is semantically incorrect. The postfix increment operator should return the value before incrementing. In other words something like this should have been compiled instead:

const id = modalId.current; // 0
modalId.current = modalId.current + 1; // 1
return id;

This bug does not trigger when the incremented value is a plain primitive, instead there is a TODO bailout.

@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Jun 11, 2025
@poteto poteto force-pushed the pr33508 branch 3 times, most recently from ee2c0be to c7ce9ba Compare June 11, 2025 16:12
Copy link
Member

@josephsavona josephsavona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice find!

Comment on lines +26 to +42
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [],
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might be able to get a runnable test (that fails the forget/no-forget comparison) by using effects that setState w the result of the increment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just did a console log for now so sprout catches it. I added this fixture to the sprout filter.

This bug was reported via our wg and appears to only affect values created as a ref.

Currently, postfix operators used in a callback gets compiled to:

```js
modalId.current = modalId.current + 1; // 1
const id = modalId.current; // 1
return id;
```

which is semantically incorrect. The postfix increment operator should return the value before incrementing. In other words something like this should have been compiled instead:

```js
const id = modalId.current; // 0
modalId.current = modalId.current + 1; // 1
return id;
```

This bug does not trigger when the incremented value is a plain primitive, instead there is a TODO bailout.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants