LearnNewsExamplesServices
Frontmatter
id7686
titleEnhance `button.Base` handler config for proper reactivity with closures
stateClosed
labels
bugenhancementai
assigneestobiu
createdAtNov 1, 2025, 11:42 AM
updatedAtNov 1, 2025, 11:52 AM
githubUrlhttps://github.com/neomjs/neo/issues/7686
authortobiu
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtNov 1, 2025, 11:51 AM

Enhance button.Base handler config for proper reactivity with closures

Closed v11.0.0 bugenhancementai
tobiu
tobiu commented on Nov 1, 2025, 11:42 AM

Problem

The handler_ config in Neo.button.Base was experiencing a bug where, in recycled components (e.g., in a buffered grid), the handler function would become stale. This was due to the default Neo.isEqual (which performs a deep comparison) incorrectly determining that a new handler function (with a new closure) was identical to the old one, preventing the config system from triggering an update.

Solution

The fix involves adding a descriptor to the handler_ config in src/button/Base.mjs. This descriptor overrides the isEqual method to specifically handle function comparisons. If both the old and new handler values are functions, isEqual now returns false, forcing the config system to always treat a new function instance as a change. For other types (e.g., strings), it defaults to strict equality.

Rationale for isEqual override

Standard JavaScript closure behavior means that two function instances, even with identical source code, can close over different variables. The default deep comparison in Neo.isEqual cannot reliably detect this difference. Overriding isEqual ensures that new function instances are always considered a change, preventing stale closures in recycled components.

JSDoc Update

The JSDoc for the handler_ config in src/button/Base.mjs should be updated to explain this behavior and the rationale behind the isEqual override.

tobiu added the bug label on Nov 1, 2025, 11:42 AM
tobiu added the enhancement label on Nov 1, 2025, 11:42 AM
tobiu added the ai label on Nov 1, 2025, 11:42 AM
tobiu referenced in commit 78c0f33 - "Enhance button.Base handler config for proper reactivity with closures #7686" on Nov 1, 2025, 11:51 AM
tobiu closed this issue on Nov 1, 2025, 11:51 AM
tobiu assigned to @tobiu on Nov 1, 2025, 11:52 AM