Skip to content

修复<button>标签嵌套的错误#9

Open
Pectics wants to merge 1 commit into
chmod777john:chore/specs-mvpfrom
Pectics:fix/nested-button
Open

修复<button>标签嵌套的错误#9
Pectics wants to merge 1 commit into
chmod777john:chore/specs-mvpfrom
Pectics:fix/nested-button

Conversation

@Pectics
Copy link
Copy Markdown

@Pectics Pectics commented Feb 4, 2026

我使用了DeepSeek的deepseek-reasoner模型做测试,修改了相应的BASE_URL、API_KEY,使用中发现让Agent操作子Agent的时候,Next会报一些<button>标签嵌套的错误。

本PR对该问题进行了简单修复。

详细报错内容如下:

Error 1/2:

## Error Type
Console Error

## Error Message
In HTML, <button> cannot be a descendant of <button>.
This will cause a hydration error.

  ...
    <RedirectErrorBoundary router={{...}}>
      <InnerLayoutRouter url="/im?worksp..." tree={[...]} params={{}} cacheNode={{rsc:<Fragment>, ...}} ...>
        <SegmentViewNode type="page" pagePath="im/page.tsx">
          <SegmentTrieNode>
          <ClientPageRoot Component={function IMPage} serverProvidedParams={{...}}>
            <IMPage params={Promise} searchParams={Promise}>
              <Suspense fallback={<div>}>
                <IMPageInner>
                  <IMShell left={<aside>} mid={<main>} right={<Fragment>}>
                    <div className="app dark">
                      <aside className="panel pane...">
                        <div>
                        <div>
                        <div className="list">
>                         <button className="row active" onClick={function onClick} style={{paddingLeft:16}}>
                            <div style={{display:"flex", ...}}>
                              <div style={{display:"flex", ...}}>
>                               <button type="button" className="tree-caret" onClick={function onClick} title="收起">
                                ...
                            ...
                          ...
                          ...
                      ...
        ...
      ...



    at button (<anonymous>:null:null)
    at renderGroupRow (.next\dev\static\chunks\app_im_34711470._.js:1955:255)
    at <unknown> (.next\dev\static\chunks\app_im_34711470._.js:2227:122)
    at Array.map (<anonymous>:null:null)
    at IMPageInner (.next\dev\static\chunks\app_im_34711470._.js:2227:43)
    at IMPage (.next\dev\static\chunks\app_im_34711470._.js:307:221)

Next.js version: 16.1.6 (Turbopack)

Error 2/2:

## Error Type
Console Error

## Error Message
<button> cannot contain a nested <button>.
See this log for the ancestor stack trace.


    at button (<anonymous>:null:null)
    at renderGroupRow (.next\dev\static\chunks\app_im_34711470._.js:1908:218)
    at <unknown> (.next\dev\static\chunks\app_im_34711470._.js:2227:122)
    at Array.map (<anonymous>:null:null)
    at IMPageInner (.next\dev\static\chunks\app_im_34711470._.js:2227:43)
    at IMPage (.next\dev\static\chunks\app_im_34711470._.js:307:221)

Next.js version: 16.1.6 (Turbopack)

Copilot AI review requested due to automatic review settings February 4, 2026 15:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a React hydration error caused by nested <button> elements in the IM page. The issue occurred when rendering group rows with tree structures, where a collapse/expand button was nested inside a row button, violating HTML semantics.

Changes:

  • Replaced the outer <button> element with a <div> element using role="button" for accessibility
  • Added keyboard navigation support with tabIndex={0} and onKeyDown handler for Enter and Space keys
  • Maintained the same visual behavior and click functionality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Pectics Pectics changed the title Fixed a nesting button error 修复<button>标签嵌套的错误 Feb 4, 2026
Copy link
Copy Markdown

@leuasseurfarrelds247-arch leuasseurfarrelds247-arch left a comment

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants