Skip to content

Commit 402881f

Browse files
fzdwxclaude
andcommitted
fix: update event handlers on React re-render
Event handlers were not being updated in commitUpdate, causing click handlers to capture stale closure values. Now re-registers handlers on each update to ensure the latest state is captured. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent df3870c commit 402881f

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/reconciler/host-config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,22 @@ export const hostConfig: HostConfig<
303303
nextProps: Props,
304304
_internalHandle: OpaqueHandle
305305
): void {
306+
let needsUpdate = false;
307+
308+
// Update text content
306309
if (nextProps && typeof nextProps.children === "string") {
307310
instance.text = String(nextProps.children);
311+
needsUpdate = true;
312+
}
313+
314+
// Update event handlers - re-register to capture new closure values
315+
const newHandlers = extractEventHandlers(nextProps);
316+
for (const [eventType, handlerId] of Object.entries(newHandlers)) {
317+
bindEventToElement(instance.id, eventType, handlerId);
318+
}
319+
instance.eventHandlers = newHandlers;
320+
321+
if (needsUpdate) {
308322
const element = instance.store.getElement(instance.id);
309323
if (element) {
310324
queueElementUpdate(element);

0 commit comments

Comments
 (0)