QwikDev / qwik

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

[🐞] Warned useOnXXX even for not empty components. #2980

Closed genki closed 1 year ago

genki commented 1 year ago

Which component is affected?

Qwik Runtime

Describe the bug

When using useOnXXX in the component that including components like this:

export default component$(() => {
  useOnDocument("DOMContentLoaded", $(() => {
    ...
  }));
  return (
    <>
    <Link href="/">Test</Link>
    </>
  );
});

it is warned

QWIK WARN Component has listeners attached, but it does not render any elements, injecting a new <script> element to attach listeners.

I think this warning is a bit surplus.

Reproduction

https://stackblitz.com/edit/qwik-starter-uhcukh?file=src/routes/index.tsx

Steps to reproduce

Please see the reproduction link.

System Info

System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M2
    Memory: 78.86 MB / 24.00 GB
    Shell: 3.5.1 - /opt/homebrew/bin/fish
  Binaries:
    Node: 19.5.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.3.1 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 109.0.5414.119
    Edge: 110.0.1587.41
    Firefox: 109.0.1
    Safari: 16.2
  npmPackages:
    @builder.io/qwik: file:../clone/qwik/packages/qwik => 0.17.6 
    @builder.io/qwik-city: file:../clone/qwik/packages/qwik-city => 0.1.1 
    undici: 5.14.0 => 5.14.0

Additional Information

No response

stackblitz[bot] commented 1 year ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

zanettin commented 1 year ago

Hi @genki 👋 Thanks for creating this issue 🙏 Imo the error is correct in that case. Fragments are nothing that will be projected on the DOM so there is no way technically to attach a listener to it. What would be the expected solution from your point of view?

genki commented 1 year ago

@zanettin I expect the warning is not necessary because the <script> tag insertion works. I think it is not so special to make intermediate components consist of only child components without normal HTML tags.

zanettin commented 1 year ago

Hi @genki Thanks a lot for your reply 🙏

I expect the warning is not necessary because the Githubissues.

  • Githubissues is a development platform for aggregating issues.