Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
anishkumar127 opened this issue Dec 4, 2024 · 7 comments
Open
2 tasks done

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

anishkumar127 opened this issue Dec 4, 2024 · 7 comments

Comments

@anishkumar127
Copy link

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.
@spmonahan
Copy link
Contributor

spmonahan commented Dec 4, 2024

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

StackBlitz is a good way to set this up.

@anishkumar127
Copy link
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

@spmonahan
Copy link
Contributor

This is because react-components does not currently support React 19. See: https://github.com/microsoft/fluentui/blob/master/packages/react-components/react-components/package.json#L82

React 19 will be supported in the future.

@tudorpopams and @dmytrokirpa for visibility.

@vlad-ivanov-d
Copy link

@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.

@vlad-ivanov-d
Copy link

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(""),
  );
}

@koltyakov
Copy link

@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.

@spmonahan
Copy link
Contributor

@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.

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

No branches or pull requests

4 participants