Skip to content

[Bug]: @fluentui/react-motion: Invalid child element. #33404

Closed

Description

Component

Drawer

Package version

^9.56.3

React version

19.0.0-rc-66855b96-20241106

Environment

System:
    OS: Windows 11 10.0.22631
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i3-1125G4 @ 2.00GHz
    Memory: 2.34 GB / 15.65 GB
  Browsers:
    Edge: Chromium (130.0.2849.52)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @fluentui/react-components: ^9.56.3 => 9.56.3
    @fluentui/react-icons: ^2.0.266 => 2.0.266
    @types/react: ^18.3.12 => 18.3.12
    @types/react-dom: ^18.3.1 => 18.3.1
    react: 19.0.0-rc-66855b96-20241106 => 19.0.0-rc-66855b96-20241106
    react-dom: 19.0.0-rc-66855b96-20241106 => 19.0.0-rc-66855b96-20241106

Current Behavior

Crashing application

  • when im trying to use Drawer in next.js 15. it's saying
    Error: @fluentui/react-motion: Invalid child element. Motion factories require a single child element to be passed. That element element should support ref forwarding i.e. it should be either an intrinsic element (e.g. div) or a component that uses React.forwardRef().

Image

Expected Behavior

it's should work.

Reproduction

don't have the link

Steps to reproduce

Install next.js 15.
Use the fluent ui 9 latest version
and try to use the drawer

Are you reporting an Accessibility issue?

None

Suggested severity

Urgent - No workaround and Products/sites are affected

Products/sites affected

No response

Are you willing to submit a PR to fix?

yes

Validations

  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • The provided reproduction is a minimal reproducible example of the bug.

Activity

  1. spmonahan commented on Dec 4, 2024

    @spmonahan
    Contributor

    Anish Kumar (@anishkumar127) Please provide a repro link so I can take a look.

    StackBlitz is a good way to set this up.

  2. anishkumar127 commented on Dec 5, 2024

    @anishkumar127
    Author

    @anishkumar127 Please provide a repro link so I can take a look.

    StackBlitz is a good way to set this up.

    Link: https://stackblitz.com/edit/stackblitz-starters-m3ccwj?description=The%20React%20framework%20for%20production&file=next%2Fpackage.json&title=Next.js%20Starter

    even now i'm not able to install npm install @fluentui/react-components with the next.js 15 it's saying this on terminal.

    Image

  3. spmonahan commented on Dec 5, 2024

    @spmonahan
    Contributor
  4. vlad-ivanov-d commented on Dec 14, 2024

    @vlad-ivanov-d

    Sean Monahan (@spmonahan) it doesn't work even with React 18 and Next.js 15. So this issue is not related to React 19.

    The problem is in isForwardRef func right here:

    if (typeof child.type === 'string' || ReactIs.isForwardRef(child)) {

    All components are Symbol(react.transitional.element) in Next.js (I guess because of SSR stuff). That's why this check always fails.

  5. vlad-ivanov-d commented on Dec 17, 2024

    @vlad-ivanov-d

    This is how I workaround this (dirty hack). Basically I had to replace getChildElement.js with my patched version.

    in package.json I added this script:
    "postinstall": "cp src/tools/getChildElement.js node_modules/@fluentui/react-motion/lib/utils/getChildElement.js"

    src/tools/getChildElement.js:

    import * as React from "react";
    import * as ReactIs from "react-is";
    export function getChildElement(children) {
      try {
        const child = React.Children.only(children);
        if (
          typeof child.type === "string" ||
          ReactIs.isForwardRef({
            ...child,
            /**
             * Patch type because of issues with Next.js
             * https://github.com/microsoft/fluentui/issues/33404
             */
            ["$$typeof"]:
              child["$$typeof"] === Symbol.for("react.transitional.element") ? Symbol.for("react.element") : child["$$typeof"],
          })
        ) {
          return child;
        }
        // We don't need to do anything here: we catch the exception from React to throw a more meaningful error
        // eslint-disable-next-line no-empty
      } catch {}
      throw new Error(
        [
          "@fluentui/react-motion: Invalid child element.",
          "\n",
          "Motion factories require a single child element to be passed. ",
          "That element element should support ref forwarding i.e. it should be either an intrinsic element (e.g. div) or a component that uses React.forwardRef().",
        ].join(""),
      );
    }
    
  6. koltyakov commented on Dec 19, 2024

    @koltyakov

    Sean Monahan (@spmonahan) any update on this? Did you guys manage to check the possible solution?

    Next.js and SSR are the hot topic. It would be great seeing Fluent UI compatible with the top notch technologies.

  7. spmonahan commented on Dec 19, 2024

    @spmonahan
    Contributor

    Andrew Koltyakov (@koltyakov) , I was just triaging the issue to get it into the correct backlog so no further updates from me 🙂. Given the season I wouldn't expect anyone to pick this up before January.

  8. it950 commented on Jan 4, 2025

    @it950

    In React Router v7, the error still exists when a component use Drawer:
    Image

  9. wnbittle commented on Jan 6, 2025

    @wnbittle

    I have the same problem. The work around above didn't work for me since I'm using pnpm, but this did:

    "postinstall": "cp src/tools/getChildElement.js node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/@fluentui/react-motion/lib/utils"
  10. rlamtabbet commented on Feb 14, 2025

    @rlamtabbet

    I encountered this issue with the OverlayDrawer and the Drawer when using the overlay type with React 19. Switching the same drawer to the inline type works as expected.
    Finally downgraded to React 18 and the overlay worked as expected.

  11. ellorenz2 commented on Mar 4, 2025

    @ellorenz2

    Using Visual Studio 2022 and React 19
    \node_modules@fluentui\react-motion\lib\factories\createPresenceComponent.js:19:35
    node_modules@fluentui\react-context-selector\lib\createContext.js:7:45)
    react-dialog\lib\components\Dialog\Dialog.js:12:19)
    node_modules@fluentui\react-drawer\lib\components\OverlayDrawer\OverlayDrawer.js:10:19)
    TextDirectionProvider
    packages\react\src\TextDirectionContext.tsx:21:79)
    at FluentProvider (https//../node_modules/.vite/deps/@fluentui_react-components.js?v=6e8f36c8:12170:17) {name: 'Error Component Stack', stack: 'Error Component Stack:
    at Object.assign (…ntui_react-components.js?v=6e8f36c8:12170:17)', message: ''}

  12. boldbaatar-dx commented on Mar 10, 2025

    @boldbaatar-dx

    Is there any solution for this?

  13. ropre4 commented on Mar 11, 2025

    @ropre4

    I ran into this issue with NextJS 15, React 19, with "Dialog" react-component.

    I must say, big THANK YOU to Vlad Ivanov (@vlad-ivanov-d) , as his hack is still the only soution to this

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions