fix(convert-chip): fix hooks order when toggling layout mode#45
fix(convert-chip): fix hooks order when toggling layout mode#45qiuwenbo1 wants to merge 1 commit into
Conversation
… 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.
3f0a687 to
7d7059a
Compare
|
Heads-up: PRs #28 and #30 are also open against this same You, @chasel34, and @cszhouwei may want to compare approaches; the maintainer team will pick which one lands. Sharing so nobody's effort gets wasted. |
|
|
||
| // 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; |
There was a problem hiding this comment.
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.
Summary
Rendered fewer hooks than expectedwhen switching layout between split / editor / preview.if (layoutMode !== "split") return nullto afteruseCallbackanduseEffectinConvertChip.Test plan
pnpm dev, open the app