-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Button]: onClick not working in Next.js client component #10751
Comments
Hi @Mau04 Thanks for reporting! I'll forward this issue to our UI5 Web Components Colleagues as the affected component is developed in their repository. As a workaround, you can delay the rendering of the ui5 web component. E.g. by using Hi Colleagues, The bug seems to be a race condition, as I wasn't able to reproduce the behavior every time, but I managed to create a setup, that should show the bug most of the time: https://stackblitz.com/edit/github-jednsxqe-trgqrudq?file=app%2Fbutton-test.component.tsx Reproduction steps
2025-02-03_12-49-09.mp4In case you can't reproduce the issue, you can try the following:
|
Hi @ui5-webcomponents-topic-core, Please check the reported issue, it probably affects all components. Best Regards, |
Hi @Lukas742 , React example <not-found onMyEvent={console.log}></not-found> ![]() I was expecting Preact example <not-found onMyEvent={console.log}></not-found> ![]() Compared to react, the tag is rendered and the event handler is attached. React debugging I could find the starting point of this process by checking where the onClick property is handled and found it comes from listenToAllSupportedEvents(container); This method is looping through an array called My conclusion is that react hydration is attaching only native event handlers by going through a hardcoded list of known browser events. Next steps I see two ways forward:
By the way, this whole investigation was for the SelectionChange event which is clearly a custom event name. For the onClick event, it doesn't work because you are technically passing What do you think? |
Hi @pskelin this helped a lot, thanks!
You are correct, using
Yes, I now believe this is why the issue went undetected for so long. If any React state or prop change occurs, the component updates, revalidating all props, including handler props. In @Mau04's example, the Fixing the issueWe will first implement a workaround in our wrapper function by ensuring the component only renders on the client: if(typeof window === "undefined"){
return null;
} Next, I'll open a GitHub issue - either with React or Next.js (as it's easier to reproduce there) - but I’m not sure yet when I’ll find the time for this. |
The workaround is now live and can be consumed with v2.7.1 of https://stackblitz.com/edit/github-jednsxqe-xpegfhzd?file=app%2Fpage.tsx,package.json |
I just tried v2.7.1 in my project and now I'm running into a hydration error, because the server side rendering does not match the re-rendering on client side:
The same happens to me in your Stackblitz. I also tried my example in Next.js 14 and it worked fine, so I guess something changed between Next.js 14 -> 15 and/or React 18 -> 19. |
@Mau04 Currently, there will always be a diff between the markup on the server and the markup on the client. You can find out more about it in this issue. That's why we're using When returning
The difference is the React version. Next.js 15 App Router is using React 19 under the hood (even before there was a stable release) and since React 19 (mostly) supports custom elements, much of our wrapper logic was removed. With React 18 this does not occur, because event listener are added by our wrapper, not by React. |
Describe the bug
I added a button in a client component and added an onClick handler, but the onClick handler is not called.
If I add a standard HTML button and add an onClick handler, it works. After clicking this button once, the UI5 button works, too.
Isolated Example
https://stackblitz.com/edit/github-jednsxqe?file=app%2Fpage.tsx,app%2Flayout.tsx
Reproduction steps
Expected Behaviour
The handler should be called.
Screenshots or Videos
No response
UI5 Web Components for React Version
2.6.0
UI5 Web Components Version
2.6.3
Browser
Chrome
Operating System
macOS
Additional Context
No response
Relevant log output
Organization
SAP
Declaration
The text was updated successfully, but these errors were encountered: