Skip to content

fix(convert-chip): fix hooks order when toggling layout mode#45

Closed
qiuwenbo1 wants to merge 1 commit into
nexu-io:mainfrom
qiuwenbo1:fix/convert-chip-hooks-order
Closed

fix(convert-chip): fix hooks order when toggling layout mode#45
qiuwenbo1 wants to merge 1 commit into
nexu-io:mainfrom
qiuwenbo1:fix/convert-chip-hooks-order

Conversation

@qiuwenbo1
Copy link
Copy Markdown

@qiuwenbo1 qiuwenbo1 commented May 16, 2026

Summary

  • Fixes Rendered fewer hooks than expected when switching layout between split / editor / preview.
  • Moves if (layoutMode !== "split") return null to after useCallback and useEffect in ConvertChip.

Test plan

  • pnpm dev, open the app
  • Toggle layout: split → editor → preview → split; no hook errors in console
  • Convert chip visible only in split mode
  • ⌘/Ctrl+Enter still triggers convert when enabled

… crash

React requires hooks to run in the same order every render. Returning null
before useCallback/useEffect when layoutMode !== "split" caused "Rendered
fewer hooks than expected" when switching between split and editor/preview.
@qiuwenbo1 qiuwenbo1 force-pushed the fix/convert-chip-hooks-order branch from 3f0a687 to 7d7059a Compare May 16, 2026 12:32
@lefarcen lefarcen requested a review from mrcfps May 16, 2026 12:33
@lefarcen lefarcen added size/XS Extra-small change (<20 lines) risk/medium Medium risk change type/bugfix Bug fix labels May 16, 2026
@lefarcen
Copy link
Copy Markdown

Heads-up: PRs #28 and #30 are also open against this same ConvertChip hook-order fix. All three touch src/components/convert-chip.tsx and move the layoutMode !== "split" guard below the hook calls for the “Rendered fewer hooks than expected” crash.

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

Copy link
Copy Markdown

@mrcfps mrcfps left a comment

Choose a reason for hiding this comment

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

Thanks for the hooks-order fix — I found one follow-up shortcut regression in editor-only mode; details are inline.

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


// Only show in split mode — when only one pane is visible there's no
// divider to hang off, and the toolbar button is already obvious.
if (layoutMode !== "split") return null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Keeping the hooks unconditional fixes the React crash, but moving this guard below the useEffect also leaves the global ⌘/Ctrl+Enter listener active when the chip is hidden in editor-only mode. EditorPane still renders AiPromptBar there (src/components/editor-pane.tsx:147), and that input already handles the same shortcut without stopping propagation (src/components/ai-prompt-bar.tsx:57-61), so a single keypress now both submits the draft and starts an HTML conversion from a hidden chip. That is a behavior regression from the pre-change flow. Please keep the hooks unconditional but gate the keydown effect itself on layoutMode === "split" (or ignore events coming from the prompt input / stop propagation there), and add a regression check for ⌘/Ctrl+Enter in editor mode.

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

@qiuwenbo1 qiuwenbo1 closed this May 16, 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.

3 participants