QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.78k stars 1.29k forks source link

[🐞] Imported image causes onclick$ to duplicate like crazy #5520

Open DidrikBje opened 10 months ago

DidrikBje commented 10 months ago

Which component is affected?

Qwik Runtime

Describe the bug

I recently changed my <img /> to imported image tags, e.g <ImportedImage />, in which I found this weird behaviour. On the image there is a click-listener which works properly when it's just an img tag, but when its the imported image tag, the onClick$ gets fired an amount of times more for each click. So first click its fired once, then twice, then maybe 5, then 10 etc. In the example below, clicking on the left button 5 times then the right one 5 times causes it to fire 70-100 times. Depends on how fast you click for some reason. Clicking only the right one 5 times, it gets fired up to 25 times.

This specifically happens when the onclick$ is adding an element to an array within a useStore(), and the array gets mapped out to html on the same page.

If on the other hand the imported image tag is wrapped into a <div> and the div gets the onclick$ instead, this behaviour won't happen. So it seem to me to be a bug related between useStore() and the import image as JSX thingy.

Reproduction

https://stackblitz.com/edit/qwik-starter-tqvtin?file=src%2Froutes%2Findex.tsx

Steps to reproduce

This behaviour happened both during testing localhost and when built and deployed to a domain.

System Info

System:
    OS: macOS 12.5
    CPU: (8) arm64 Apple M2
    Memory: 71.52 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.1/bin/npm
  Browsers:
    Chrome: 119.0.6045.199
    Safari: 15.6
  npmPackages:
    @builder.io/qwik: ^1.2.19 => 1.2.19 
    @builder.io/qwik-city: ^1.2.19 => 1.2.19 
    @builder.io/qwik-react: 0.5.0 => 0.5.0 
    undici: ^5.26.0 => 5.28.2 
    vite: ^4.4.11 => 4.5.0

Additional Information

I hope the report was done properly, haven't made one before :)

wmertens commented 10 months ago

sounds like something about the click adds listeners but doesn't clear them :thinking: