nivo icon indicating copy to clipboard operation
nivo copied to clipboard

Warning: Support for defaultProps will be removed from function components

Open donfour opened this issue 11 months ago • 11 comments

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:

  • https://github.com/recharts/recharts/issues/3615
  • https://github.com/chakra-ui/chakra-ui/issues/7057

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.

donfour avatar Aug 17 '23 18:08 donfour

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 ❤️

RobertAron avatar Aug 30 '23 14:08 RobertAron

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

bernatfortet avatar Sep 18 '23 22:09 bernatfortet

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 :(

andre19980 avatar Oct 20 '23 18:10 andre19980

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 avatar Jan 29 '24 09:01 dreampulse

Hello!

Any update on this issue?

ClydSpyd avatar Feb 09 '24 18:02 ClydSpyd

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

andre19980 avatar Feb 14 '24 18:02 andre19980

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

plouc avatar Mar 04 '24 00:03 plouc

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?

emiliodacosta avatar Mar 29 '24 05:03 emiliodacosta

image

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

rahul8864 avatar Apr 23 '24 03:04 rahul8864

Something similar is happening at https://github.com/recharts/recharts/issues/3615

edu-amr avatar May 06 '24 17:05 edu-amr