backstage icon indicating copy to clipboard operation
backstage copied to clipboard

Updates recharts to v2.0.0 and fixes typing issues

Open leonardomaier opened this issue 3 years ago • 8 comments

Hey, I just made a Pull Request!

Upgraded recharts to v2.0.0 and fixed all typing issues

Relates to #12609

:heavy_check_mark: Checklist

  • [x] A changeset describing the change and affected packages. (more info)
  • [x] Added or updated documentation
  • [x] Tests for new functionality and regression tests for bug fixes
  • [x] Screenshots attached (for UI changes)
  • [x] All your commits have a Signed-off-by line in the message. (more info)

leonardomaier avatar Sep 03 '22 14:09 leonardomaier

Unexpected Changesets

The following changeset(s) reference packages that have not been changed in this PR:

  • .changeset/selfish-kiwis-matter.md: @backstage/create-app

Note that only changes that affect the published package require changesets, for example changes to tests and storybook stories do not require changesets.

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/cli packages/cli patch v0.20.0
@backstage/plugin-bitrise plugins/bitrise patch v0.1.37
@backstage/plugin-code-coverage plugins/code-coverage patch v0.2.3
@backstage/plugin-cost-insights plugins/cost-insights minor v0.11.32
@backstage/plugin-git-release-manager plugins/git-release-manager patch v0.3.23
@backstage/plugin-xcmetrics plugins/xcmetrics patch v0.2.30

github-actions[bot] avatar Sep 03 '22 14:09 github-actions[bot]

You'll see that CI now says to move @types/recharts to devDependencies, which is a good thing!

freben avatar Sep 05 '22 09:09 freben

@freben I just made some changes, let me know what you think 😄

leonardomaier avatar Sep 05 '22 19:09 leonardomaier

So, BuildTimeline.test.tsx tests are broken.

I took a look, and it seems to be caused by a recharts lib dependency called react-resize-detector which was on version v2.3.0 before the upgrade. After upgrading recharts, it goes to version 7.1.2 which is a huge jump.

I found out this already happened with other people, and a code snippet was added to the documentation as you can see here:

https://github.com/maslianok/react-resize-detector#testing-with-enzyme-and-jest

After adding the code snippet to the test suite, it worked fine but I got some TS errors:

image

Not sure if there is any solution to that besides ignoring the error, but I'll dig into it.

leonardomaier avatar Sep 06 '22 12:09 leonardomaier

Found an interesting discussion related to the CI error:

https://github.com/recharts/recharts/commit/3115b4d869042f7daf94a267117f75adc5049e23

Still trying out some approaches.

leonardomaier avatar Sep 06 '22 18:09 leonardomaier

Upgrading recharts lib to v2.0.0 brought problems related to its dependencies. For example, recharts use d3-* (array, shape, interpolation, etc...) as a dependency and at some point, d3 files were published as modules that broke the jest transform pipeline.

I ran all tests locally and the following error was thrown:

.../node_modules/d3-array/src/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export * from "d3-array";
SyntaxError: Unexpected token 'export'

In some way, jest wasn't able to resolve the dependencies from d3, so I followed what they did in this issue thread which is a very similar error. I've added all d3 libs in the moduleNameMapper in jest.js and it worked fine.

Besides that, I added the ResizeObserver in some additional component tests, related to react-resize-detector upgrade like I mentioned here.

Btw, all checks went green. Finally.

leonardomaier avatar Sep 06 '22 21:09 leonardomaier

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If you are the author and the PR has been closed, feel free to re-open the PR and continue the contribution!

github-actions[bot] avatar Sep 13 '22 21:09 github-actions[bot]

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If you are the author and the PR has been closed, feel free to re-open the PR and continue the contribution!

github-actions[bot] avatar Sep 21 '22 21:09 github-actions[bot]

I just tried to push a change without the mapping, just to see what CI does of it

freben avatar Sep 23 '22 08:09 freben

Going to dig into it a little bit more and search for alternatives.

leonardomaier avatar Sep 29 '22 14:09 leonardomaier

@freben I've made some changes:

  • To solve issues related to d3-* libs, I removed the parser config for tsx files on jest.js (based on this thread)
  • After the change mentioned above, the LogoIcon.jsx component started to fail, and after some research, I realized that we don't use the jsx extension for our components, so I changed it to tsx. Not sure if it was defined that way by mistake, but I fixed it.
  • BuildTimeline component tests were failing due to the ResponsiveContainer component from recharts, so I needed to mock it and it solved the problem.

Besides that, you can see that a check failed, but it doesn't seem to be related to these changes. Let me know what you think.

leonardomaier avatar Oct 01 '22 14:10 leonardomaier

Note that the top of the LogoIcon file says

// @ts-check
// NOTE: This file is intentionally .jsx, so that there is one file in this repo where we make sure .jsx files work.

So that one is really meant to be jsx so that we can check that those flows work too...

freben avatar Oct 02 '22 13:10 freben

@freben you're right, I'll undo this change.

I've found an interesting issue on the SWC repository that was tagged as a bug:

https://github.com/swc-project/swc/issues/4911

The error above is what happens if I keep the parser for .tsx files, so maybe there is nothing we can do right now.

leonardomaier avatar Oct 03 '22 12:10 leonardomaier

Ah yeah great find! The playground link in the repo concurs with you ... maybe we can put this one on ice for a little bit and hope that an swc update fixes things for us soon. Annoying that you hit these roadblocks, but we're grateful for the thoroughness and investigations around it!

freben avatar Oct 03 '22 14:10 freben

Referencing the PR that might unblock this: https://github.com/swc-project/swc/pull/6067

leonardomaier avatar Oct 06 '22 14:10 leonardomaier

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If you are the author and the PR has been closed, feel free to re-open the PR and continue the contribution!

github-actions[bot] avatar Oct 13 '22 14:10 github-actions[bot]

Looks like the fix is planned to be released in [email protected]

leonardomaier avatar Oct 17 '22 09:10 leonardomaier

@freben upgraded to [email protected] and it fixed the parsing issue. All checks have passed, by the way.

leonardomaier avatar Oct 17 '22 14:10 leonardomaier

Thanks for the contribution! All commits need to be DCO signed before they are reviewed. Please refer to the the DCO section in CONTRIBUTING.md or the DCO status for more info.

backstage-goalie[bot] avatar Oct 18 '22 21:10 backstage-goalie[bot]

All green ✅

leonardomaier avatar Oct 19 '22 12:10 leonardomaier

Thank you for contributing during Hacktoberfest 🍂! You can claim the Backstage Hacktoberfest Holopin at https://bck.st/hacktoberfest-holopin 🙌🏻

suuus avatar Oct 24 '22 20:10 suuus