Skip to content

fix(modal): prevent onClose$ from firing on initial mount when show is false#1175

Merged
maiieul merged 3 commits intoqwikifiers:mainfrom
FHachez:claude/strange-dhawan-423190
Apr 17, 2026
Merged

fix(modal): prevent onClose$ from firing on initial mount when show is false#1175
maiieul merged 3 commits intoqwikifiers:mainfrom
FHachez:claude/strange-dhawan-423190

Conversation

@FHachez
Copy link
Copy Markdown
Contributor

@FHachez FHachez commented Apr 17, 2026

Summary

  • onClose$ was being called on the initial useTask$ run whenever the modal started in a closed state (bind:show = false), because the task unconditionally fell into the else branch on first execution.
  • Added a wasOpenSig flag that is set to true the first time the modal opens. onClose$ is now only invoked after a real open → closed transition.
  • onShow$ behavior is unchanged.

Root cause

In Qwik, useTask$ runs once on mount to register tracking, then re-runs on signal changes. On the first run with showSig.value === false, the previous code hit the else branch and called onClose$ — even though the modal had never been open.

…s false

onClose$ should only be called after an open→close transition, not during
the initial useTask$ run when the modal starts in a closed state.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 17, 2026

🦋 Changeset detected

Latest commit: aeed3c8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@qwik-ui/headless Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 17, 2026

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@FHachez FHachez marked this pull request as draft April 17, 2026 14:57
@FHachez
Copy link
Copy Markdown
Contributor Author

FHachez commented Apr 17, 2026

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Apr 17, 2026
Covers the bug where onClose$ was called on initial mount when the modal
starts closed. Tests verify callbacks fire only after real open/close
transitions and accumulate correctly across multiple cycles.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 17, 2026

Open in StackBlitz

npm i https://pkg.pr.new/qwik-ui@1175
npm i https://pkg.pr.new/@qwik-ui/headless@1175
npm i https://pkg.pr.new/@qwik-ui/styled@1175
npm i https://pkg.pr.new/@qwik-ui/utils@1175

commit: 70e43f1

@maiieul maiieul marked this pull request as ready for review April 17, 2026 17:48
@maiieul maiieul merged commit 3fda36b into qwikifiers:main Apr 17, 2026
1 check passed
@github-actions github-actions Bot mentioned this pull request Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants