8000 #191 Upgrade Chakra UI to v3 by nevendyulgerov · Pull Request #221 · cartesi/explorer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

#191 Upgrade Chakra UI to v3 #221

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nevendyulgerov
Copy link
Contributor
@nevendyulgerov nevendyulgerov commented May 12, 2025

I upgraded chakra from v2 to v3. This required major changes in the UI code base in order for us to utilize the v3 components. Summary of the changes:

  • Removed v2 theme configs for components and replaced them with v3 recipes.
  • Remove obsolete npm packages.
  • Updated all pages to utilize the new v3 components.
  • Tweaked some chakra v3 components so they match the UI we used before (this includes local changes as well as global recipes).
  • Added npm script chakra-types for generating TS types for custom variants that we use in our codebase.
  • Added step in the CI build and Vercel build for running the chakra-types script.
  • Removed unused components and related unit tests and stories for them.
  • Added comments in the PR where additional context may be required for the reviewer to understand some changes.

Copy link
vercel bot commented May 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 12, 2025 8:01pm

Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License

View full report

@@ -16,6 +16,9 @@ jobs:
- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Install chakra-ui types
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This step generates the custom chakra-ui variants. This is a prerequisite for a successful build as otherwise we'll get ts errors for invalid variants which will fail the build.


describe('CTSI Text component', () => {
it('Should render the formatted amount of CTSI', () => {
render(<CTSIText value="5000100000000000000000000" />);
render(<Component value="5000100000000000000000000" />);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to refactor some of the tested component so that they are always augmented with the chakra-ui context. Otherwise those tests were failing.

userEvent.hover(icon);
});

await screen.findByText(tooltip);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The userEvent package is useful for interacting with tooltips, number inputs and similar composite components. The fireEvent api from react testing library doesn't trigger mouseover / change events for those components correctly.

);

expect(screen.getByText('Wallet is disconnected')).toBeInTheDocument();
expect(screen.getByText('Connect To Wallet')).toBeInTheDocument();
});

it('should display default accent colour and different accents based on status', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test was tightly coupled with the alert styles and was flaky between chakra v2 and v3. Also, it was just testing if chakra was correctly styling the Alert component based on the passed status. We can trust chakra to do its thing without us testing it. That's why I removed it.

@@ -38,7 +38,7 @@ module.exports = {
'<rootDir>/.vscode/',
'<rootDir>/public/',
],
testEnvironment: 'jsdom',
testEnvironment: './fixJSDOMEnvironment.ts',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was required because jsdom was failing with errors for missing structuredClone function (introduced in node v17). The error caused all unit tests to fail.

@@ -6,8 +6,8 @@
"dev": "run-s db:dev:migrate next:dev",
"build": "run-s db:prod:migrate next:build",
"start": "next start",
"next:build": "next build",
"next:dev": "next dev",
"next:build": "npm run chakra-types && next build",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Running the chakra-types npm script is a requirement for the next build to succeed. I added it to the dev script also so that no ts errors, related to custom variants, are produced when you start your local dev environment.

@@ -154,11 +154,11 @@ const BigNumberTextV2: FC<BigNumberTextV2Props> = (props) => {
>
{valueLabel}
</Heading>
{unit && value && (
{unitLabel !== '' && unit && value && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixed an issue with short-circuiting that was causing unitLabels with 0 value to appear in this part of the UI.

@@ -118,7 +126,7 @@ export const Card = ({
<Button
data-testid="card-action-button"
ml={{ base: 0, lg: 2 }}
colorScheme={colorScheme}
colorPalette={colorScheme}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

colorScheme is not replaced by colorPalette for all instances in the code.

...lastValue,
...data.stakingPoolFeeHistories,
]);
setList((lastValue) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed an issue with the fee histories when you disconnected and then reconnected your wallet. In this case the fee histories were being duplicated. This fixes the issue.

import { defineSlo 8000 tRecipe } from '@chakra-ui/react';
import { alertAnatomy } from '@chakra-ui/react/anatomy';

export const alertRecipe = defineSlotRecipe({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a recipe for alerts so that the UI matches the one we used before.

import { defineSlotRecipe } from '@chakra-ui/react';
import { radioGroupAnatomy } from '@chakra-ui/react/anatomy';

export const radioGroupRecipe = defineSlotRecipe({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a recipe for radio inputs to match the UI we used before.

@nevendyulgerov nevendyulgerov self-assigned this May 12, 2025
@nevendyulgerov nevendyulgerov added the type:feature new feature or improvement over an existing feature label May 12, 2025
@nevendyulgerov nevendyulgerov marked this pull request as ready for review May 13, 2025 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature new feature or improvement over an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0