Closed jwickers closed 2 weeks ago
Start a new pull request in StackBlitz Codeflow.
Thanks a lot @jwickers and sorry for the delay
If this isn't fixed by now, it'll definitely be easier to solve in V2 I believe
We'll add a test for it in the V2 branch to verify this is not repeating
I'm closing this since it's fixed in v2. We're hoping to get the alpha out soon.
Which component is affected?
Qwik Runtime
Describe the bug
There is a weird interaction between component event handlers like
useOn
,useOnDocument
oruseOnWindow
and the JSX structure.Reproduction
You can see this stackblitz as well: https://stackblitz.com/edit/qwik-starter-mkqcen?file=src%2Froutes%2Findex.tsx
Press any key on the page to start and see both components render the events counts. Press the escape key to switch the component render which changes the behavior.
BUG 1
When the component renders fragment, Qwik places a
<script type="placeholder"
tag with the Qwik event handlers (likeon-document:xxx
). If the component changes to render a DIV for example, that placeholder is removed and the DIV now has the event handlers. So far so good. But if the component renders back to a fragment then the DIV is not replaced back with a placeholder tag thus losing the event handlers altogether.BUG 2
An easy workaround seems to be to avoid using a fragment as root in the JSX and say wrap the whole component in a DIV. But when the component changes to render an inner DIV, that inner DIV then also gets the event handlers, causing those events to be processed twice.
Reproduction
https://github.com/jwickers/qwik-useon-events-bug
Steps to reproduce
Run
npm install
andnpm run start
.System Info
Additional Information
No response