Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
Bug: React 19 does not attach custom element event listeners during hydration | GoodFirstPicks

Bug: React 19 does not attach custom element event listeners during hydration

facebook/react 5 comments 1mo ago
View on GitHub
highopenScope: somewhat clearSkill match: maybeReactJavaScriptTypeScript

Why this is a good first issue

This issue involves React's hydration mechanism and custom elements, requiring deep React internals knowledge.

AI Summary

The issue describes a bug where React does not attach event listeners for custom element events during hydration, only after the first client render. This affects SSR frameworks like Next.js. The fix likely requires changes to React's hydration logic, which is complex and requires deep understanding of React internals.

Issue Description

When hydrating server-rendered markup, React does not attach event listeners for custom element events that have been configured on the custom element using the React's on<custom event name> prop syntax. The event handler is only attached after the first client render, not during hydration. This issue affects all React SSR frameworks like Next.js (linking a related issue from Next.js: https://github.com/vercel/next.js/issues/84091 - note that the issue is on React side).

React version: 19.2.3

Steps To Reproduce

  1. Open the CodeSandbox example.
  2. Click the first "Emit custom event" button.
  3. Click the second "Emit custom event" button.

Link to code example: https://codesandbox.io/p/devbox/thirsty-leaf-4n6r2t

Description of the demo

The CodeSandbox simulates SSR + hydration using only React:

  • Server HTML is generated via renderToString
  • The markup is injected into the DOM
  • hydrateRoot is used to hydrate the content

A custom element <my-element>:

  • Uses Shadow DOM
  • Dispatches a CustomEvent("my-event") when clicking the "Emit custom event" button

Each React component (NotWorking & WorksWithForcedRerender) renders:

<my-element
  onmy-event={() => {
    console.log(
      "React custom event handler fired from <component name> component"
    );
    alert("React custom event handler fired from <component name> component");
  }}
/>

The current behavior

The onmy-event prop on <my-element> in <NotWorking> React component does not call the configured callback function and does not cause a native alert to pop up because React does properly attach event listener for the onmy-event prop during hydration.

However, the onmy-event prop on <my-element> in <WorksWithForcedRerender> React component properl

GitHub Labels

Status: Unconfirmed

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!

Risk Flags

  • requires deep React internals knowledge
  • SSR/hydration complexity
  • custom elements integration
Loading labels...

Details

Points10 pts
Difficultyhigh
Scopesomewhat clear
Skill Matchmaybe
Test Focusedno