•  


Support React 19 · Issue #4558 · recharts/recharts · GitHub
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

Support React 19 #4558

Open
justinh00k opened this issue May 20, 2024 · 21 comments
Open

Support React 19 #4558

justinh00k opened this issue May 20, 2024 · 21 comments
Labels
feature request Issues that are feature requests P0 Critical priority issues

Comments

@justinh00k
Copy link

justinh00k commented May 20, 2024

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Charts do not render when using React 19, or when using NextJS 14.3 (which uses React 19).

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via codesandbox or similar (template: https://codesandbox.io/p/sandbox/simple-line-chart-v25dl4 ).

Install react@rc or react@beta
Observe charts do not render
https://github.com/justinh00k/recharts-react19-repro

What is the expected behavior?

Charts render

Which versions of Recharts, and which browser / OS are affected by this issue? Did this work in previous versions of Recharts?

2.12.7 / No

@ckifer
Copy link
Member

ckifer commented May 20, 2024

React 19 will be added to peerDependencies when recharts supports it.

Please see #4542 and #3615

Edit: Current alpha https://www.npmjs.com/package/recharts/v/2.13.0-alpha.4

@ckifer
Copy link
Member

Going to edit the title if you don't mind to just "Support React 19", and use this to track support in 2.x

@ckifer ckifer changed the title Does Not Support React 19 Support React 19 May 20, 2024
@ckifer
Copy link
Member

Alpha release - https://www.npmjs.com/package/recharts/v/2.13.0-alpha.0
This BREAKS things in R19, shouldn't in R18

use this to determine what is breaking/what isn't. I just don't have bandwidth to fix it myself

Things that I know are broken:

Bar
Legend
Cursor
Pie

@ckifer ckifer added feature request Issues that are feature requests P0 Critical priority issues labels May 24, 2024
@ckifer
Copy link
Member

ckifer commented May 24, 2024

https://www.npmjs.com/package/recharts/v/2.13.0-alpha.2
Should have more R19 support if not all of it (minus the need to disregard peerDeps and install react-is@19)

Please test this one as well on all React versions 16.8-19 to see if anyone runs into issues. Thanks! ??

@ckifer
Copy link
Member

In order to use React 19 one must override the react-is version. This will always be true in 2.x. 3.x we will add react-is to peerDeps or remove it entirely

  "overrides": {
    "react-is": "^19.0.0-beta-26f2496093-20240514"
  }

@rauchg
Copy link

appreciate your work @ckifer

@ckifer
Copy link
Member

ckifer commented May 26, 2024

Appreciate @eps1lon and next helping out a bit here @rauchg !

@juliusmarminge
Copy link

juliusmarminge commented May 26, 2024

Just tried on Next.js RC (React 19.0.0-rc-f994737d14-20240522) and my beautiful charts are back. Thank you ??

EDIT: Or maybe not? Some breaking types? Adding an @ts-expect-error for now I guess

CleanShot 2024-05-26 at 22 26 12@2x

@rauchg
Copy link

My only issue remaining is <Legend /> started rendering incorrectly, but it might be skill issue. I'm using Tremor, so maybe it's related to their impl and the version bump.

@ckifer
Copy link
Member

ckifer commented May 26, 2024

@juliusmarminge Not sure why the types broke, are there React 19 types released? I can't seem to reproduce. But might need to add explicit children

Also noticed that @rauchg - I think probably another defaultProps issue that hasn't been caught yet. Will take another look

Edit: for Legend for now you can just add the defaultProps back yourself (not sure if you can do this in Tremor)

        <Legend iconSize={14} layout="horizontal" align="center" verticalAlign="bottom" />

@ckifer
Copy link
Member

ckifer commented May 27, 2024

Legend:

  • This still uses defaultProps incorrectly (doesn't include them)
  • This also causes issues (props not combined)

@emanuele-moricci
Copy link

I've also noticed a particular difference only when updating from recharts@latest to recharts@alpha-2 + react@rc :

I have an AreaChart (without set height/width) wrapped with ResponsiveContainer:

<ResponsiveContainer width="98%" height="98%">
            <AreaChart data={data} margin={{ right: 0, left: 0 }}>
...

image

After updating though, the same exact code does not render the graph in any way

image

I have tried with both set/dynamic dimensions on the AreaChart component, ResponsiveContainer or the other wrapping html tags (following the examples on the docs website) but the chart either doesn't render at all or loses all the responsive features it had before.

Is this also true on your end?
If there's anything I can do (or share of my config) to help, I'm at your disposal.

@ckifer
Copy link
Member

@emanuele-moricci this sounds like your version of react-is hasn't been overridden #4558 (comment)

Try to npm ls react-is and see if it gives you multiple versions.

@emanuele-moricci
Copy link

And you'd be right! For future reference:
I updated every occurrence of react-is by hand in my package-lock (I use PNPM) since the overrides features was not getting nested packages even when explicitly written.

After that, I cancelled the node_modules folder and fired pnpm install , and it worked! Thank you for the assistance ????

@eps1lon
Copy link
Contributor

You definitely need to force react-is@rc either via resolutions (Yarn) or overrides (PNPM, NPM).

react-is will be a peer dependency in 3.x to fix these issues (see #4541 ). But it's a breaking change so it can't land in 2.x.

@ckifer
Copy link
Member

https://www.npmjs.com/package/recharts/v/2.13.0-alpha.3

Alpha-3 should fix the Legend issues mentioned above. Please continue to report other issues as you run into them, thanks!

@tobiaslins
Copy link

tobiaslins commented May 29, 2024

It seems like there is an issue with stacked bars. The same stackId does not stack but are overlapping
image

"next": "15.0.0-rc.0",
"react": "19.0.0-rc-6f23540c7d-20240528",
"react-dom": "19.0.0-rc-6f23540c7d-20240528",
"react-is": "19.0.0-rc-6f23540c7d-20240528",
"recharts": "2.13.0-alpha.3"
   <
Bar
 dataKey
=
"pv"
 stackId
=
"testing"
 fill
=
"#8884d8"
 /
>

   <
Bar
 dataKey
=
"uv"
 stackId
=
"testing"
 fill
=
"#82ca9d"
 /
>
const
 data
 =
 [

  {

    name
: 
"Page A"
,

    uv
: 
3000
,

    pv
: 
2401
,

  }
,

  {

    name
: 
"Page B"
,

    uv
: 
100
,

    pv
: 
1398
,

  }
]

@ckifer
Copy link
Member

Thanks @tobiaslins will look into it

@ckifer
Copy link
Member

@tobiaslins I can reproduce here https://codesandbox.io/p/sandbox/stacked-bar-chart-7fwfgj
But I can't reproduce in the recharts repo and I'm not sure why. Makes debugging these issues difficult - if anyone wants to help feel free

@ckifer
Copy link
Member

ckifer commented May 31, 2024

const axisId : AxisId = item . props [ numericAxisId ] ;

This is why stacks fail - we expect an axisId to be present but it isn't getting defaulted because of the way defaulProps are read. This one doesn't seem as reasonable to refactor as the other ones so for now specifying axisIds on you graphical items and axes should fix it. Will work on a fix in the meantime

ckifer added a commit that referenced this issue Jun 2, 2024
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->
Safely re-add defaultProps to places where props are being read directly
from graphical items to fix issues with current alpha release

Fixes stacked bars and stacked areas. maybe more

## Related Issue

<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please link to the issue here: -->
#4558


## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->
support react 19 in 2.x. Lots of defaultProps issues

## How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
See tests added. These now pass in R19 and 18

## Screenshots (if appropriate):

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [X] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [X] I have added tests to cover my changes.
- [ ] I have added a storybook story or extended an existing story to
show my changes

---------

Co-authored-by: Coltin Kifer <ckifer@amazon.com>
@ckifer
Copy link
Member

https://www.npmjs.com/package/recharts/v/2.13.0-alpha.4
Alpha 4 fixes the ReferenceLine typing issue and fixes stacked Bar and Area charts.

@tobiaslins should be good to go now

Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment
Labels
feature request Issues that are feature requests P0 Critical priority issues
Projects
None yet
Development

No branches or pull requests

7 participants
- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본