Repository navigation
fix(devtools): keep hook statements in braceless bodies compiling - #9156
Open
Aejkatappaja wants to merge 5 commits into
Open
Aejkatappaja wants to merge 5 commits into
Aejkatappaja wants to merge 5 commits into
Conversation
Tracking a hook called as the statement of a braceless if, else or loop body produced 'if (x) let ...' or put collecthook between the if and its else. Wrap the statement and its tracking in a block there, and track with inserts only so edits for nested hooks never overlap.
🦋 Changeset detectedLatest commit: 33418db The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
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 |
@qwik.dev/core
@qwik.dev/router
@qwik.dev/utils
eslint-plugin-qwik
create-qwik
@qwik.dev/optimizer
@qwik.dev/devtools
@qwik.dev/mcp
commit: |
Aejkatappaja
marked this pull request as ready for review
October 13, 2026 10:28
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is it?
Description
With DevTools or MCP enabled, a component that calls a hook as a statement in a braceless
if,elseor loop body stops compiling, or silently tracks the wrong thing:When the statement's parent isn't a statement list (program, block, static block,
case), the hook and itscollecthookcall now go in a block. Statements already in a block come out exactly as before, so the existing snapshot doesn't change.While in there I switched the hook tracking to inserts only. A custom hook used to be rewritten with a
replaceof the whole statement, computed on the original text, so a hook called inside another hook's callback (if (c) useTask$(() => { useFoo(); });) produced broken output once the inner edit had shifted things. Inserting{ let _customhook_0 =before the statement and; collecthook(...) }after it never overlaps another edit.applySourceEditsalso keeps inserts that share a position in the order they were added, otherwiseuseTask$(() => {});useLogger();(no space) put theletin front of the previouscollecthookand tracked its return value instead.Not covered here: a hook in a
vardeclaration directly in a braceless body (if (a) var v = useSignal(0);), and a hook in afor (...)header. Both were already broken and need the declaration path to know its grandparent, which I'd rather do separately.Tests: the braceless
if/elsecases for custom and known hooks, a hook nested in another hook's callback, and adjacent statements. The output is parsed with oxc and must have no errors, and running the transform twice gives the same result.Checklist
pnpm change