fix: remove prop mutation during render in ToolingTable#2119
Open
UtkarshSingh-06 wants to merge 3 commits intojson-schema-org:mainfrom
Open
fix: remove prop mutation during render in ToolingTable#2119UtkarshSingh-06 wants to merge 3 commits intojson-schema-org:mainfrom
UtkarshSingh-06 wants to merge 3 commits intojson-schema-org:mainfrom
Conversation
- Fix main logo alt text from 'Dynamic image' to descriptive text - Fix tool logos to use dynamic tool names instead of generic 'landscape logos' - Mark decorative icons as presentation-only (6 instances in StyledMarkdownBlock) - Fix table of contents menu icon alt text - Fix blog post images with generic 'image' alt text - Update Cypress tests to match new alt text Addresses missing and generic alt text for image elements throughout the website to meet WCAG 2.1 Level AA standards. Closes json-schema-org#2053
- Add line breaks for long chain in logo test (line 74)
- Add line breaks for should('exist') in accessibility test (line 408)
Fixes Prettier formatting issues in CI workflow
- Remove mutation of tool.bowtie during render (lines 182-185 and 278-282) - Pass bowtieData as a prop to ToolingDetailModal instead of mutating tool object - Compute bowtieData when opening modal and store in state - Fixes React immutability violation that could cause issues with Strict Mode Closes json-schema-org#2052
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2119 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 30 30
Lines 633 633
Branches 196 196
=========================================
Hits 633 633 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Remove Direct Prop Mutation During Render
Closes #2052
What kind of change does this PR introduce? This PR fixes a React anti-pattern where props were being mutated during render, which violates React's immutability principles and can cause unpredictable behavior with Strict Mode and concurrent rendering.
Summary
This PR removes direct prop mutation in
ToolingTable.tsxwheretool.bowtiewas being set during render. Instead, we now computebowtieDataand pass it as a prop toToolingDetailModal, maintaining React's immutability principles.Problem
Props were being mutated during render in two locations:
Why This Is Problematic
Solution
Instead of mutating the
toolobject, we now:bowtieDatawhen opening the modalToolingDetailModalChanges Made
1. ToolingTable.tsx
bowtieDatafor the selected toolopenModalto compute and storebowtieDatawhen opening modalcloseModalto clearbowtieDatastatebowtieDataas prop toToolingDetailModal2. ToolingDetailModal.tsx
bowtieDataprop to receive bowtie data instead of reading fromtool.bowtietool.bowtietobowtieDatapropBowtieDatatype import for proper typingCode Changes
Before
After
Testing
Expected Behavior
bowtieDatais computed and used directly in JSXbowtieDataas a prop and displays it correctlyFiles Changed
pages/tools/components/ToolingTable.tsx- Removed prop mutations, added state managementpages/tools/components/ToolingDetailModal.tsx- Updated to receivebowtieDataas propRisk Assessment
Risk Level: VERY LOW
Benefits
bowtieDataReady for review! 🚀