Skip to content

[🐞]Maybe more friendly UX when useTask throws an error #7514

Closed
@JerryWu1234

Description

@JerryWu1234

Which component is affected?

Qwik Runtime

Describe the bug

useTask$(({ cleanup }) => {
    const handleKeyPress = (e) => {
      if (e.key === "`" && e.metaKey) {
        state.isOpen.value = !state.isOpen.value;
      }
      if (e.key === "Escape" && state.isOpen.value) {
        state.isOpen.value = false;
      }
    };
    const handleClickOutside = (e) => {
      if (state.isOpen.value && panelRef.value && !panelRef.value.contains(e.target)) {
        state.isOpen.value = false;
      }
    };
    if (!isBrowser) return;
    window.addEventListener("keydown", handleKeyPress);
    window.addEventListener("mousedown", handleClickOutside);
    cleanup(() => {
      window.removeEventListener("keydown", handleKeyPress);
      window.removeEventListener("mousedown", handleClickOutside);
    });
  });

Image

if this useTask executes in server end, but which includes some client codes, and then the terminals will throws an error.
I'd better we could give a tips for user.
something likes "Please wrap the code with isBrowser to ensure it only runs on the client side."

Reproduction

https://qwik.new/

Steps to reproduce

No response

System Info

latest

Additional Information

No response

Metadata

Metadata

Assignees

Labels

COMMUNITY: good first issueGood for newcomersCOMMUNITY: PR is welcomedWe think it's a good feature to have but would love for the community to help with the PR for itCOMP: DXDeveloper Experience related issueTYPE: bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions