[🐞] Removing a conditional element re-inserts its later siblings (iframes reload, focus is lost)
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- typescript
- Domain
- frontend
Research direction
Start with the linked reproduction repository (tuurbo/qwik-rc-conditional-removal-repro) and the MutationObserver removal and insertion order it describes, using a section containing a conditional p, an iframe and a button. The bug lives in how the Qwik Runtime reconciles sibling DOM nodes after a conditional child is removed, so the work is in the runtime's rendering path, not in the example. Done means that removing the p produces only a single removed node, and that the iframe keeps its state and the button keeps focus.
Written by the indexing model from the issue text.
Description
Which component is affected?
Qwik Runtime
Describe the bug
When a conditional element is removed, Qwik also removes and re-adds every element after it. Re-inserting an <iframe> reloads it, and re-inserting a focused element drops focus.
const show = useSignal(false);
<section>
{show.value && <p>Message</p>}
<iframe srcdoc={frame} />
<button onClick$={() => (show.value = !show.value)}>Toggle message</button>
</section>
A MutationObserver on the <section>, while hiding the <p>:
removed <iframe>
removed <button>
added <iframe>
added <button>
removed <p>
Expected: only removed <p>. Showing the <p> is a single added <p>.
Reproduction
https://stackblitz.com/github/tuurbo/qwik-rc-conditional-removal-repro https://github.com/tuurbo/qwik-rc-conditional-removal-repro
Steps to reproduce
pnpm install && pnpm dev- Open
/. Note the time inside the frame. - Click Toggle message twice. The frame's time changes: it reloaded.
- Tab to the button and press Space twice. Focus ends on
<body>.
System Info
OS: Windows 11
Node: 26.10.0
pnpm: 12.9.1
@qwik.dev/core: 2.0.0-rc.2
@qwik.dev/router: 2.0.0-rc.2
vite: 8.3.3
Additional Information
Real-world impact: our payment page has Braintree hosted card fields (iframes) placed after an error message. Clearing the error on resubmit reloads the iframes losing the users entered card data.
Workarounds that keep the siblings in place: wrap the conditional so nothing follows it in its parent (<div>{show.value && <p>Message</p>}</div>), move it into its own component$, or always render it and toggle hidden.
Possibly related: #8694 (a <dialog> loses its top-layer state after an action submit, which fits it being re-inserted).
- Dominant language
- TypeScript
- Stars
- 22.1k
- Forks
- 1.4k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 99
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from QwikDev/qwik
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
[🐞] SSG: "Qwik Router SSG was skipped" warning on every SSG build, while pages are prerenderedPossibly taken @itsnjstyle27 claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
docs router V2
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
DX enhancement V2
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
QwikDev/qwik#8480 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
Maintainers usually reply within 1 day
Similar issues
-
area:frontend kind:bug priority:p2 ready
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
handsontable/hyperformula#1879 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
RunestoneInteractive/rs#1661 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
capricorn86/happy-dom#2594 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day