Skip to content

fix(convert-chip): move early return after all hook calls#28

Merged
pftom merged 1 commit into
nexu-io:mainfrom
chasel34:fix/convert-chip-hooks-order
May 17, 2026
Merged

fix(convert-chip): move early return after all hook calls#28
pftom merged 1 commit into
nexu-io:mainfrom
chasel34:fix/convert-chip-hooks-order

Conversation

@chasel34

Copy link
Copy Markdown
Contributor

Summary

  • Early return on layoutMode !== "split" was placed before useCallback
    and useEffect, violating React's Rules of Hooks and causing a runtime
    crash ("Rendered fewer hooks than expected") whenever the layout mode was
    not split.
  • Moved all hook calls above the conditional return.
  • Added an inline if (layoutMode !== "split") return guard inside
    useEffect so the ⌘+Enter keydown listener is only registered when the
    chip is actually visible.

Test plan

  • Switch to split mode — ConvertChip renders, ⌘+Enter triggers convert.
  • Switch to editor-only or preview-only mode — no crash, chip hidden,
    ⌘+Enter does nothing.
  • Hard-reload in each layout mode — no hook-count mismatch error in console.

🤖 Generated with Claude Code

Early return before useCallback/useEffect violated React's Rules of
Hooks, causing "Rendered fewer hooks than expected" at runtime when
layoutMode was not "split". Move the guard to after all hooks; add an
inline layoutMode check inside useEffect so the keydown listener is
only registered in split mode.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lefarcen lefarcen requested a review from mrcfps May 15, 2026 13:23
@lefarcen lefarcen added size/XS Extra-small change (<20 lines) risk/medium Medium risk change type/bugfix Bug fix labels May 15, 2026

@mrcfps mrcfps left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chasel34 I verified the hook-order fix in src/components/convert-chip.tsx: all hooks now run before the split-mode early return, and the useEffect listener is now gated on layoutMode === "split" so the shortcut is cleaned up when that pane layout is hidden. I couldn't run next build in this worktree because dependencies are not installed here (next: command not found), but the changed diff itself looks correct. Thanks for tightening this up 🙌

🔁 Powered by Looper · runner=reviewer · agent=opencode · An autonomous AI dev team for your GitHub repos.

@lefarcen

Copy link
Copy Markdown

Heads-up: PR #30 is also open against this same slice — both PRs touch src/components/convert-chip.tsx and target the ConvertChip hook-order crash from #26.

You and @cszhouwei may want to compare approaches; the maintainer team will pick which one lands. Sharing so neither effort gets wasted.

@lefarcen

Copy link
Copy Markdown

Additional heads-up: PR #45 is now open for the same ConvertChip hook-order slice. It also touches src/components/convert-chip.tsx and moves the non-split layout guard below the hook calls.

Keeping the cross-link here so reviewers and authors can compare the overlapping fixes in one place.

@lefarcen

Copy link
Copy Markdown

Additional heads-up: PR #50 is now open and also touches src/components/convert-chip.tsx for the same ConvertChip hook-order slice.

PR #50 bundles that fix with agent parser updates, so keeping the cross-link here should help reviewers compare whether the smaller focused fix or the broader compatibility PR should land.

@lefarcen

Copy link
Copy Markdown

Additional heads-up: PR #52 is now open and also touches src/components/convert-chip.tsx for the same ConvertChip hook-order slice.

PR #52 bundles that fix with Codex parser/output compatibility updates, so keeping the cross-link here should help reviewers compare the focused hook-order fix in this PR against the broader compatibility PR.

@pftom pftom merged commit 3db8975 into nexu-io:main May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk/medium Medium risk change size/XS Extra-small change (<20 lines) type/bugfix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants