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

fix: React props errors #4692

Merged
merged 3 commits into from
Dec 19, 2024
Merged

fix: React props errors #4692

merged 3 commits into from
Dec 19, 2024

Conversation

usame-algan
Copy link
Member

What it solves

Fixes several React errors in the console

How to test it

  1. Create new Safe and open the network selector
  2. Observe no errors in the console
  3. Create new transaction and open the address book input and nonce form
  4. Observe no errors in the console
  5. Open the app and observe no "empty href is passed to prop" error
  6. Go to the Settings page
  7. Observe no ref error for Tabs and Tabs are still keyboard navigatable

Checklist

  • I've tested the branch on mobile 📱
  • I've documented how it affects the analytics (if at all) 📊
  • I've written a unit/e2e test for it (if applicable) 🧑‍💻

Copy link

github-actions bot commented Dec 19, 2024

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code review by ChatGPT

.yarnrc Outdated Show resolved Hide resolved
<EthHashInfo address={option.label} name={option.name} shortAddress={false} copyAddress={false} />
</Typography>
)
}}
renderInput={(params) => (
<AddressInput
data-testid="address-item"

Choose a reason for hiding this comment

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

The use of destructuring to extract key from props is unnecessary as key is not needed for the child components. Remove destructuring and pass props directly: return (<Typography {...props} data-testid="address-item" ...> This keeps the code concise and aligned with best practices.

}: ExplorerButtonProps): ReactElement => {
}: ExplorerButtonProps): ReactElement | null => {
if (!href) return null

return isCompact ? (
<Tooltip title={title} placement="top">
<IconButton

Choose a reason for hiding this comment

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

Ensure href is included in the ExplorerButtonProps type definition. This prevents type errors and makes the purpose of the check clear. If href is not a required prop, consider if null is the appropriate fallback behavior or if a default action is preferable.

</Typography>
}
/>
</NextLink>
))}
</Tabs>
)

Choose a reason for hiding this comment

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

Removing NextLinkComposed simplifies the code but using legacyBehavior is deprecated and should be avoided. Refactor using Link from mui to ensure compatibility and accessibility. Direct usage of NextLink in Tab removes focus management for keyboard users.

Copy link
Member Author

Choose a reason for hiding this comment

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

No it doesn't

<ChainIndicator chainId={chain.chainId} inline />
</Box>
)
}}
getOptionLabel={(option) => option.chainName}
getOptionDisabled={isOptionDisabled}
renderInput={(params) => (

Choose a reason for hiding this comment

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

Consider extracting the renderOption function into a separate component to improve readability and reusability. Adopting this approach not only aligns with the DRY principle but also enhances code clarity and maintainability.

{isRecommendedNonce && <NonceFormHeader>Recommended nonce</NonceFormHeader>}
{isInitialPreviousNonce && <NonceFormHeader sx={{ pt: 3 }}>Replace existing</NonceFormHeader>}
<NonceFormOption key={option} menuItemProps={props} nonce={option} />
<NonceFormOption menuItemProps={rest} nonce={option} />
</div>
)
}}

Choose a reason for hiding this comment

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

Consider renaming key to something more descriptive like optionKey for clarity, given its significance in React's reconciliation. Check the safety of destructuring props without knowing its complete structure; ensure it doesn't remove required properties.

Copy link

github-actions bot commented Dec 19, 2024

📦 Next.js Bundle Analysis for safe-wallet-web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 1011.35 KB (🟡 +2 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Twenty Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/apps 29.65 KB (🟢 -79 B) 1.02 MB
/apps/custom 27.71 KB (🟢 -79 B) 1.01 MB
/balances 29.71 KB (🟢 -102 B) 1.02 MB
/balances/nfts 9.55 KB (🟢 -92 B) 1020.9 KB
/new-safe/advanced-create 26.45 KB (🟡 +14 B) 1.01 MB
/new-safe/create 25.58 KB (🟡 +16 B) 1.01 MB
/new-safe/load 6.08 KB (🟡 +23 B) 1017.43 KB
/settings/appearance 2.24 KB (🟢 -90 B) 1013.59 KB
/settings/cookies 1.86 KB (🟢 -93 B) 1013.22 KB
/settings/data 1.79 KB (🟢 -88 B) 1013.14 KB
/settings/environment-variables 3.27 KB (🟢 -89 B) 1014.62 KB
/settings/modules 4.05 KB (🟢 -76 B) 1015.4 KB
/settings/notifications 21.31 KB (🟢 -73 B) 1.01 MB
/settings/safe-apps 14.22 KB (🟢 -87 B) 1 MB
/settings/security 2.32 KB (🟢 -95 B) 1013.67 KB
/settings/setup 30.73 KB (🟢 -82 B) 1.02 MB
/transactions 93.08 KB (🟢 -72 B) 1.08 MB
/transactions/history 93.04 KB (🟢 -72 B) 1.08 MB
/transactions/messages 54.81 KB (🟢 -88 B) 1.04 MB
/transactions/queue 43.9 KB (🟢 -100 B) 1.03 MB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

Copy link

github-actions bot commented Dec 19, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
74.07% (+0.01% 🔼)
14476/19544
🔴 Branches
51.72% (+0.01% 🔼)
3449/6669
🔴 Functions
57.14% (+0.01% 🔼)
2057/3600
🟡 Lines
75.6% (+0% 🔼)
13128/17365
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🔴
... / index.tsx
36.56% (-0.4% 🔻)
11.43% 13.64%
36.78% (-0.43% 🔻)

Test suite run success

1729 tests passing in 236 suites.

Report generated by 🧪jest coverage report action from 70a9c29

Comment on lines -184 to -199
<button
aria-label=""
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-1vbp2rr-MuiButtonBase-root-MuiIconButton-root"
data-mui-internal-clone-element="true"
data-testid="explorer-btn"
rel="noreferrer"
tabindex="0"
target="_blank"
type="button"
>
<mock-icon
aria-hidden=""
class="MuiSvgIcon-root MuiSvgIcon-fontSizeSmall css-tqxw8e-MuiSvgIcon-root"
focusable="false"
/>
</button>
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not rendered anymore in the snapshot because we are not mocking the chain and with my change, the explorer link is not rendered anymore if there is no href

@katspaugh katspaugh merged commit ad43394 into dev Dec 19, 2024
14 of 15 checks passed
@katspaugh katspaugh deleted the react-warnings branch December 19, 2024 14:47
@github-actions github-actions bot locked and limited conversation to collaborators Dec 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants