Skip to content

[Bug]: Invalid hook call on pressing Tab in ComposedModal with focus-wrap-without-sentinels #19386

Closed
@fukudasjp

Description

@fukudasjp

Package

@carbon/react

Browser

No response

Package version

v1.82.1

React version

No response

Description

After pressing Tab key on Composed modal with focus-wrap-without-sentinels, an invalid hook call error Uncaught Error: Minified React error #321; visit https://react.dev/errors/321 for the full message or use the non-minified dev environment for full errors and additional helpful warnings. logged in console. Keyboard focus moves outside of the modal by pressing Tab or shift-Tab multiple times.

Log in console

      detail: Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
      1. You might have mismatching versions of React and the renderer (such as React DOM)
      2. You might be breaking the Rules of Hooks
      3. You might have more than one copy of React in the same app
      See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
          at Object.throwInvalidHookError (...node_modules/react-dom/cjs/react-dom.development.js:15408:9)
          at Object.useEffect (...node_modules/react/cjs/react.development.js:1634:21)
          at Object.wrapFocusWithoutSentinels (...node_modules/@carbon/react/lib/internal/wrapFocus.js:103:9)
          at handleKeyDown (...node_modules/@carbon/react/lib/components/ComposedModal/ComposedModal.js:164:19)
          at HTMLUnknownElement.callCallback (...node_modules/react-dom/cjs/react-dom.development.js:4164:14)

Reproduction/example

https://react.carbondesignsystem.com/?path=/story/components-composedmodal-feature-flags--enable-experimental-focus-wrap-without-sentinels

Steps to reproduce

  1. Open the storybook ComposedModal > Feature Flags > enable-experimental-focus-wrap-without-sentinels https://react.carbondesignsystem.com/?path=/story/components-composedmodal-feature-flags--enable-experimental-focus-wrap-without-sentinels
  2. Open browser console
  3. Type Tab key, and see the console
Uncaught Error: Minified React error #321; visit https://react.dev/errors/321 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at Object.throwInvalidHookError (3372.85349052.iframe.bundle.js:2:84838)
    at exports.useEffect (index.js:3517:1)
    at wrapFocusWithoutSentinels (3160.4b349720.iframe.bundle.js:1:158454)
    at handleKeyDown (5724.76c208bb.iframe.bundle.js:1:101903)
    at processDispatchQueue (3372.85349052.iframe.bundle.js:2:289344)

Suggested Severity

None

Application/PAL

No response

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions