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

performance: replace recharts charting lib with Chart.js #12952

Merged
merged 57 commits into from
Jun 25, 2024

Conversation

nhsz
Copy link
Member

@nhsz nhsz commented May 13, 2024

This PR replaces the recharts charting lib with Chart.js, with the goal of providing a lighter alternative and reduce the bundle size.

We currently have 2 types of charts on the site, the /StatsBoxGrid/GridItem on the homepage and EnergyConsumptionChart

Description

  • components
    • updates src/components/StatsBoxGrid/GridItem.tsx with Chart.js implementation
    • updates src/components/EnergyConsumptionChart.tsx with Chart.js implementation
  • hooks
    • adds useIsClient custom hook
  • misc
    • updates constants.ts
    • adds charts.ts to /lib/utils
  • updates dependencies

Charts location

Previews

Parsed size comparison

Chart.js (152.54kb)

Screen Shot 2024-05-21 at 10 51 38

recharts (271.81kb)

Screen Shot 2024-05-21 at 10 52 00

Reduction of 43.88%

Note

Found a small glitch on the StatsBox chart (don't think it's a blocker) that happens from time to time on some browsers like Chrome/Brave. Works ok on Firefox & Safari. From the comments on github, seems to be a browser issue and can't be fixed on the lib

Screen Shot 2024-06-03 at 14 17 06

Check the comments below:

@nhsz nhsz self-assigned this May 13, 2024
@github-actions github-actions bot added dependencies 📦 Changes related to project dependencies needs review 👀 labels May 13, 2024
Copy link

netlify bot commented May 13, 2024

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit 12ce1ac
🔍 Latest deploy log https://app.netlify.com/sites/ethereumorg/deploys/667aacdacc196f00088383a8
😎 Deploy Preview https://deploy-preview-12952--ethereumorg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
7 paths audited
Performance: 40 (🔴 down 7 from production)
Accessibility: 92 (no change from production)
Best Practices: 83 (🔴 down 9 from production)
SEO: 93 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added the tooling 🔧 Changes related to tooling of the project label May 13, 2024
@wackerow
Copy link
Member

Screen.Recording.2024-05-15.at.09.47.34.mov

@nhsz Noticing this when playing around. It's a fairly unnatural approach for someone to resize a window like that, but also noticing it starts getting cramped on mobile:

image
(From a larger iPhone)

@nhsz
Copy link
Member Author

nhsz commented May 15, 2024

Screen.Recording.2024-05-15.at.09.47.34.mov
@nhsz Noticing this when playing around. It's a fairly unnatural approach for someone to resize a window like that, but also noticing it starts getting cramped on mobile:

image (From a larger iPhone)

@wackerow Yes, still working on the responsive fixes, thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a couple issues here on desktop... In the Netlify preview, the homepage loads correctly showing the 30-day charts, but clicking on the 90-day button for any of them gives me the dreaded Application error: a client-side exception has occurred (see the browser console for more information).

image

Locally I do not get this, and I am able to toggle between them. I then notice a difference in our transition between 30 and 90 days, where it seems to only be showing 30 days worth of data during the transition (in both directions) leaving a dead space in the chart during the transition.

Screen.Recording.2024-05-16.at.11.47.24.mov

Is there a way to maintain all 90 days in the state while this transitions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting the same @nhsz. Locally (dev) its working fine but on the preview deploy it is crashing.


const chartOptions = {
// chart styles
barThickness: 38,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we could pass a responsive Chakra token here to make the width responsive... or perhaps we could use a maxBarThickness here to cap it on Mobile.

src/components/EnergyConsumptionChart.tsx Outdated Show resolved Hide resolved
barThickness: 38,
borderRadius: 4,
aspectRatio: 1.1,
responsive: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd that the chart doesn't re-expand if you shrink then widen the device window... Would think this would take care of it, and the Box it's contained within should be responsive... Will keep an eye out for a possible patch

src/components/EnergyConsumptionChart.tsx Outdated Show resolved Hide resolved
src/lib/constants.ts Outdated Show resolved Hide resolved
src/lib/utils/charts.ts Show resolved Hide resolved
src/components/Buttons/ButtonLink.tsx Outdated Show resolved Hide resolved
@wackerow
Copy link
Member

wackerow commented Jun 5, 2024

https://deploy-preview-12952--ethereumorg.netlify.app/en/energy-consumption

From Safari:
image

From Brave:

Screen.Recording.2024-06-05.at.11.16.26.mov
Screen.Recording.2024-06-05.at.11.22.29.mov

Cleared cache and tried this out... seeing some strange behavior on the engergy consumption chart where it glitches by loading/animating the chart twice, and seems to not be placing them in the correct sorting order. These adjust a little when the window size is adjusted.

@nhsz nhsz requested a review from pettinarip June 18, 2024 17:06
Copy link
Member

@pettinarip pettinarip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nhsz the energy consumption chart is looking better now even though it breaks when resized and the columns start to overlap a bit. I wouldn't consider this last issue as a blocker, as I doubt most users play with the window size.

One thing that could be discussed with the designers (@nloureiro @konopkja) is the height of the chart on mobile. I see that it is ~550px on the preview vs ~350px in prod. Not sure how easy it is to set it to something similar to prod.
image

====
Regarding the home page charts, I still get the error crashing the app in the preview deploy. I know that we saw that you didn't have this error yesterday but I have double checked this in different browsers (FF, chrome, brave, chrome android) and I still get the error. I'll try to debug a bit this today.

src/components/EnergyConsumptionChart.tsx Outdated Show resolved Hide resolved
@nhsz nhsz requested a review from pettinarip June 19, 2024 21:01
@wackerow
Copy link
Member

Great, the height looks good on the energy chart now. Responding well between screen sizes, I'm just still getting the double-load animation bug. I thought this was remedied with #13212 but maybe not? @pettinarip @nhsz Do you see this as a blocker?

The homepage charts are working as expected again aside from the slight difference in how it animates. No more crashes or errors when switching between 30/90-day ranges.


Small nice-to-have regarding the chart animation, right now it's anchored to the left which is a little strange since it's the right edge of the chart data that remains the same "day" (today)... would be nice if we could flip the animation anchor point to be the right edge instead.

@pettinarip
Copy link
Member

@wackerow

I'm just still getting the double-load animation bug

There is a hydration issue that is not related to this PR (its a pre-existing bug). We are going to tackle that on a separate PR.

Copy link
Member

@pettinarip pettinarip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @nhsz!

@wackerow the nice to have that you mentioned could be explored and added on a separate PR (to not block this long waiting PR), or even we could deactivate it if it doesn't convince us. Open for that as well. LMK what do you think or if you already have an idea about how we could achieve this.

Copy link
Member

@wackerow wackerow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Can tackle anything remaining in separate issue(s)

@wackerow wackerow merged commit e80543d into dev Jun 25, 2024
10 checks passed
@wackerow wackerow deleted the performance-chartjs branch June 25, 2024 14:58
This was referenced Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies 📦 Changes related to project dependencies tooling 🔧 Changes related to tooling of the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants