Skip to content

fix(convert-chip): move layout-mode guard after all hooks#30

Open
cszhouwei wants to merge 1 commit into
nexu-io:mainfrom
cszhouwei:fix/convert-chip-hook-order
Open

fix(convert-chip): move layout-mode guard after all hooks#30
cszhouwei wants to merge 1 commit into
nexu-io:mainfrom
cszhouwei:fix/convert-chip-hook-order

Conversation

@cszhouwei
Copy link
Copy Markdown
Contributor

Summary

  • ConvertChip had an early return null for non-split layouts sitting between useStore/useT and the later useCallback/useEffect hooks. Toggling layoutMode between split and editor/preview therefore changed the hook count between renders, and React threw "Rendered fewer hooks than expected" (minified #300).
  • Moves the layout-mode guard below every hook call so hook order stays stable across layout changes. No behavior change in the rendered UI.

Refs #26 — fixes symptom 1 of 3 (the other two, the deploy-control snapshot loop and the Codex agent_message parser drift, are not touched here).

Test plan

  • pnpm dev, load /, toggle layout between split / editor / preview — no React crash, chip appears only in split mode.
  • ⌘/Ctrl+Enter still triggers Convert from the chip while in split mode.
  • pnpm build (reviewer to confirm in CI).

🤖 Generated with Claude Code

The early `return null` for non-split layouts sat between `useStore`/`useT`
and the later `useCallback`/`useEffect`, so toggling layoutMode produced a
different hook count between renders and React threw "Rendered fewer hooks
than expected" (minified #300). Moving the guard below every hook call
keeps the hook order stable across layout changes.

Refs nexu-io#26 (symptom 1 of 3).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lefarcen lefarcen requested a review from Siri-Ray May 15, 2026 14:46
@lefarcen lefarcen added size/XS Extra-small change (<20 lines) risk/medium Medium risk change type/bugfix Bug fix labels May 15, 2026
@lefarcen
Copy link
Copy Markdown

Heads-up: PR #28 is also open against this same slice — both PRs touch src/components/convert-chip.tsx and move the layoutMode !== "split" guard below the hook calls for the React hook-order crash from #26.

You and @chasel34 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 this 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 this 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

Hey @cszhouwei, quick lifecycle update: PR #28 has now merged the focused ConvertChip hook-order fix for #26, and the reporter has verified that slice on current main.

That means this PR is now superseded by the merged fix. I’m routing the close for maintainer confirmation rather than asking reviewers to spend more time on the duplicate path. Thanks for jumping on this bug — the direction here matched the issue well.

@PerishCode
Copy link
Copy Markdown
Contributor

Thanks for the PR. I checked a local rebase onto the latest main, but I did not push changes to your branch because the fix appears to have already landed upstream.

What I found:

  • Current main already has the layoutMode !== "split" guard after the hooks in next/src/components/convert-chip.tsx.
  • Applying this PR on top of current main only adds a duplicate guard, so there is no remaining useful code change to preserve.

Suggested next step:

  • If this PR has no additional intended changes, it can be closed as already covered by main.
  • If you still see a related crash, please update the branch with a fresh repro and a new diff against the current next/ workspace shape.

Recommended validation for any follow-up:

  • pnpm exec tsx scripts/guard.ts
  • pnpm -F @html-anything/next typecheck
  • pnpm -F @html-anything/next build

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