Comments (7)
Appreciate the investigation! Why would Next just make Class components break? 😅 Wild.
Anyways, we're doing a lot of refactoring that should enable us to move off of class components entirely - it'll just take a while.
Thanks!
from recharts.
Hi @ckifer, thank you very much for your prompt answer. I am a bit puzzled because charts do work in server-side rendering in a Node.JS backend project. However they specifically don't in a Next.JS environment. In the above example, the same chart with the same components is server-side renderable using the test.ts script, but is not within Next.
It seems that there may be a component that detects a different runtime and triggers different rendering processes. Most notably, on our example that works server-side the generated code doesn't contain anything for tooltips but it seems that inside a Next project the Chart attempts to render tooltips hence causing the error.
Is there a way we could bypass the tooltips altogether? We have tried adding a <Tooltip content={() => null} viewBox={{x: 0, y:0, width: 0, height: 0}} />
to try and opt-out of tooltips rendering but it doesn't seem to work.
Thanks for the input anyways, much appreciated!
from recharts.
After a bit of investigating, it seems that the root cause is lack of support for Class Components for server-side rendering in Next.js. Although class components are now legacy, I think this would require a significant rewrite effort for Recharts.
Let's close this for now.
from recharts.
Recharts has no explicit support for server side rendering. It's built for the browser environment only at this point in time as we call functions such as getClientBoundingRect
and others that do not exist on the server.
"use client"; is the solution. You can separate your components so that only your charts have to render client side
from recharts.
the es6
path is probably being forced because I think Next uses the type: module
field in the package.json (not sure about that 100%). This with the combination of some magic they are doing could cause the issue I guess?
I wonder, in that Node backend project if you tried to use type: module
if you would get the same error or not
from recharts.
Both projects are actually in the same folder, the node entrypoint is at https://github.com/Titou325/dev-recharts-next/blob/main/test.ts, inside the Next app. The Next app also imports the file at https://github.com/Titou325/dev-recharts-next/blob/main/src/app/page.tsx
The two commands are npm run dev
for Next and npx tsx test.ts
for the Node backend.
I will try and see if tsx may do some shenanigans to get things working but it seems strange.
from recharts.
definitely strange.
the component in question in the error is here https://github.com/recharts/recharts/blob/master/src/component/TooltipBoundingBox.tsx#L29. Its still a class component and it doesn't have a constructor or call super
If I do call the constructor though, its useless and I shouldn't have to in order to prevent errors
from recharts.
Related Issues (20)
- AreaChart and LineChart do not show the values correctly HOT 1
- Question on exporting `useChartWidth` and similar api HOT 2
- BarChart : Without BarSize bug, with BarSize another Bug HOT 2
- Adjust the colour of the dot at the cursor of the tooltip (AreaChart) HOT 3
- Lines directly on the lower or upper bound of a Y-axis with custom domain and allowDataOverflow gets partially clipped out of view HOT 4
- Active bar and tooltip persist despite mouse cursor leaving chart area HOT 4
- Is there any way to position=insideMiddle? HOT 5
- Brush component is missing property `data` HOT 3
- Stacked chart round some bars HOT 2
- Points property not generating for Area Chart in v2.12.6 HOT 5
- recharts responsive pie chart with legend HOT 2
- BarChart dataKeys that include brackets don't work HOT 5
- Warning about defaultProps Support in XAxis HOT 4
- Area Chart + Brush: Descending data is reversed on brush HOT 9
- responsive container infers the parent div height [low priority] HOT 1
- Storybook Documentation for more visibility HOT 2
- How to make hover tooltip for each individual cell instead of XAxis column HOT 8
- X-axis times ticks are not display major hour like 11:00 12:00 HOT 9
- Auto rotate X-Axis Tick labels when the chart gets smaller HOT 3
- How to apply gradient on the opposite side of the AreaChart line HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from recharts.