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

Warning: Support for defaultProps will be removed from function components #2415

Closed
donfour opened this issue Aug 17, 2023 · 14 comments
Closed

Comments

@donfour
Copy link

donfour commented Aug 17, 2023

Describe/explain the bug
Getting the following error when using Nivo with Next.js 13 inside app router:

app-index.js:31 Warning: Jr: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.

It doesn't affect the chart rendering though. It's just a bit annoying to see a long error in the console. Other libraries are also seeing a similar issue:

Wondering if Nivo has a plan to move from defaultProps to JS default parameters? It seems like quite a large refactor. Happy to contribute if needed. Thanks!

To Reproduce
Codesandbox: https://codesandbox.io/p/sandbox/frosty-tom-fgddxp

Steps to reproduce the behavior:

  1. Go to the codesandbox
  2. Open the preview in a new tab
  3. Open dev tool console
  4. See error

Expected behavior
Rendering a chart should throw no error.

@RobertAron
Copy link

I'm running into this issue as well. The warning is quite long also, which makes it difficult to parse other logs that appear in the inspector.

I understand this could be a large refactor... If anyone has suggestions for a hack to suppress warnings about this issue temporarily I would really appreciate it ❤️

@bernatfortet
Copy link

Any updates on this?
Has anyone found a way to hide the warnings?

@andre19980
Copy link
Contributor

andre19980 commented Oct 20, 2023

I tried to do the refactor (based in the similar issue that @donfour linked to the description) but the deploy has failed and I guess I don't have access to vercel to see the logs :(

@dreampulse
Copy link

I fixed that by patching the console.log, since the warning is polluting the developer experience.
(And for me, the issue is just occurring in external libraries)

if (process.env.NODE_ENV !== "production") {
  // eslint-disable-next-line no-console
  const originalWarn = console.error;
  // eslint-disable-next-line no-console
  console.error = (...args) => {
    if (
      args[0].includes(
        "Support for defaultProps will be removed from function components in a future major release.",
      )
    ) {
      return;
    }
    originalWarn(...args);
  };
}

@ClydSpyd
Copy link

ClydSpyd commented Feb 9, 2024

Hello!

Any update on this issue?

@andre19980
Copy link
Contributor

@ClydSpyd it's waiting for a release! @plouc Any plans to release a new version soon? Is there something I can help?

@plouc
Copy link
Owner

plouc commented Mar 4, 2024

Sorry, I just didn't have the time to release, I'll try to find some time in the upcoming weeks.

@emiliodacosta
Copy link

I fixed that by patching the console.log, since the warning is polluting the developer experience. (And for me, the issue is just occurring in external libraries)

if (process.env.NODE_ENV !== "production") {
  // eslint-disable-next-line no-console
  const originalWarn = console.error;
  // eslint-disable-next-line no-console
  console.error = (...args) => {
    if (
      args[0].includes(
        "Support for defaultProps will be removed from function components in a future major release.",
      )
    ) {
      return;
    }
    originalWarn(...args);
  };
}

@dreampulse where did you put this code for it to work?

@rksahu2601
Copy link

image

I noticed the warning message only appears locally and not in production. (ReCharts)

@edu-amr
Copy link

edu-amr commented May 6, 2024

Something similar is happening at recharts/recharts#3615

@hassansw
Copy link

hassansw commented May 19, 2024

const originalConsoleError = console.error;
console.error = (message, ...args) => {
    if (typeof message === 'string' && message.includes('defaultProps will be removed')) {
        return;
    }
    originalConsoleError.apply(console, [message, ...args])
}

Done

@plouc
Copy link
Owner

plouc commented May 21, 2024

This issue has been fixed in the latest version (0.87.0).

@plouc plouc closed this as completed May 21, 2024
@fukemy
Copy link

fukemy commented Aug 23, 2024

if (process.env.NODE_ENV !== "production") {
  // eslint-disable-next-line no-console
  const originalWarn = console.error;
  // eslint-disable-next-line no-console
  console.error = (...args) => {
    if (
      args[0].includes(
        "Support for defaultProps will be removed from function components in a future major release.",
      )
    ) {
      return;
    }
    originalWarn(...args);
  };
}

Can someone guide me where to put above code? I am using NextJs

@lokichaulagain
Copy link

lokichaulagain commented Oct 26, 2024

if (process.env.NODE_ENV !== "production") {
  // eslint-disable-next-line no-console
  const originalWarn = console.error;
  // eslint-disable-next-line no-console
  console.error = (...args) => {
    if (
      args[0].includes(
        "Support for defaultProps will be removed from function components in a future major release.",
      )
    ) {
      return;
    }
    originalWarn(...args);
  };
}

Can someone guide me where to put above code? I am using NextJs

In your Next.js page where we’re using react-beautiful-dnd, we are simply hiding the warning message without fixing it. Note: This approach uses defaultProps, which may be removed in React 19, so it’s only compatible with React 18.

"use client";
import dynamic from "next/dynamic";
const DraggableList = dynamic(() => import("./(components)/DraggableList"), { ssr: false });

export default function Page() {
  //  Hide warning message from react-beautiful-dnd library
  const originalWarn = console.error;
  console.error = (...args) => {
    const warningMessage = args[0];
    if (warningMessage.includes("Support for defaultProps will be removed from function components in a future major release.") || warningMessage.includes("Support for defaultProps will be removed from memo components in a future major release.")) {
      return;
    }
    originalWarn(...args);
  };

  return (
    <div>
      <h1 className="text-xl font-bold mb-4">Draggable List</h1>
      <DraggableList />
    </div>
  );
}

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

No branches or pull requests

14 participants