The issue involves inconsistent behavior of the `<details>` element's `onToggle` event between Next.js and standard React/HTML.
The issue reports that the `<details>` element's `onToggle` event does not fire automatically on render in Next.js 14/15 when `open` is set to `true`, contrary to standard HTML and React behavior. The problem requires investigation into Next.js's handling of DOM events and potential server-side rendering implications. Recent comments suggest it might be related to client-side behavior but remain inconclusive.
https://github.com/mikedidomizio/details-element-in-Next-14
First sorry that the GitHub link is for Next14, it doesn't matter here
The <details> HTML element is an accordion style HTML tag that can show and hide information.
The onToggle event is expected to automatically fire on render if open is set to true
Documentation
In the example above the event listener will be called once without any user interaction because the open attribute is set.
Below are CodeSandbox examples, the way to see if it automatically fire is to open the developer tools console and see that a console.log is either done or not.
In HTML it works that way ✅
In React 19 it works that way ✅
In React 18 it works that way ✅
In Next.js 15 it doesn't seem to work that way 🤔
In Next.js 14 it doesn't seem to work that way 🤔
So HTML/React will automatically trigger the onToggle event on render if open is set to true, but not Next.js.
Is this a bug or am I doing something wrong with the Next example?
(Originally posted on the Discord/Forum)
https://github.com/user-attachments/assets/f70b5f76-e31a-4072-8de8-35a6ace844f6
Current behaviour:
Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!