Skip to content

#8563 Refactor: Mark the props of the component as read-only - #8622

Merged
AlexeyGirin merged 2 commits into
masterfrom
copilot/refactor-read-only-props
Nov 21, 2025
Merged

AlexeyGirin merged 2 commits into
masterfrom
copilot/refactor-read-only-props

Conversation

Copilot AI commented Nov 21, 2025 •

Copy link
Copy Markdown
Contributor

React props should be immutable to enforce unidirectional data flow and prevent child components from modifying parent state.

Changes

Wrapped props parameters with TypeScript's Readonly<> utility type in 6 functional components:

  • AtomInfo - PeriodTable atom information display
  • OutinerRow - PeriodTable row rendering
  • AboutDialog - Application about dialog
  • ErrorsCheck - Molecule validation errors display
  • FooterContent - Recognition dialog footer
  • RecognizeDialog - Structure recognition from image

Before:

function AtomInfo({ el, isInfo }: AtomInfoProps) {
  // ...
}

After:

function AtomInfo({ el, isInfo }: Readonly<AtomInfoProps>) {
  // ...
}

This prevents accidental prop mutations while maintaining identical runtime behavior.

Original prompt

This section details on the original issue you should resolve

<issue_title>Refactor: Mark the props of the component as read-only</issue_title>
<issue_description>Problem:
React props should be read-only

Why is this an issue?
React props should be read-only because it helps to enforce the principle of immutability in React functional components. By making props read-only, you ensure that the data passed from a parent component to a child component cannot be modified directly by the child component. This helps maintain a clear data flow and prevents unexpected side effects.

If props were mutable, child components could modify the props directly, leading to unpredictable behavior and making it harder to track down bugs. By enforcing read-only props, React promotes a more predictable and maintainable codebase. Additionally, read-only props enable performance optimizations in React’s rendering process by avoiding unnecessary re-renders of components.

Overall, enforcing read-only props in React helps improve code reliability, maintainability, and performance.

interface Props {
  name: string;
}

function Welcome(props: Props) { // Noncompliant: The component props are not read-only
  return <div>Hello {props.name}</div>;
}

You should use TypeScript’s utility type Readonly to make your functional component props read-only.

interface Props {
  name: string;
}

function Welcome(props: Readonly<Props>) {
  return <div>Hello {props.name}</div>;
}

Alternatively, you can use TypeScript’s modifier readonly to mark all the props of your functional component individually as read-only.

interface Props {
  readonly name: string;
}

function Welcome(props: Props) {
  return <div>Hello {props.name}</div>;
}

Problem locations:
packages/ketcher-react/src/script/ui/views/modal/components/PeriodTable/components/AtomInfo/AtomInfo.tsx:26
packages/ketcher-react/src/script/ui/views/modal/components/PeriodTable/components/ElementsTable/components/OutinerRow.tsx:31
packages/ketcher-react/src/script/ui/views/modal/components/meta/About/About.tsx:35
packages/ketcher-react/src/script/ui/views/modal/components/process/Check/components/ErrorsCheck.tsx:46
packages/ketcher-react/src/script/ui/views/modal/components/process/Recognize/Recognize.tsx:50
packages/ketcher-react/src/script/ui/views/modal/components/process/Recognize/Recognize.tsx:103</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor component props to be read-only Mark React component props as read-only Nov 21, 2025
Copilot AI requested a review from AlexeyGirin November 21, 2025 06:08
@AlexeyGirin
AlexeyGirin marked this pull request as ready for review November 21, 2025 08:17
@AlexeyGirin
AlexeyGirin requested review from svvald and removed request for AlexeyGirin, NataliaLoginova and Zhirnoff November 21, 2025 08:17
@AlexeyGirin AlexeyGirin changed the title Mark React component props as read-only #8563 Refactor: Mark the props of the component as read-only Nov 21, 2025
@AlexeyGirin
AlexeyGirin merged commit 10d97e3 into master Nov 21, 2025
15 checks passed
@AlexeyGirin
AlexeyGirin deleted the copilot/refactor-read-only-props branch November 21, 2025 11:06
AlexeyGirin added a commit that referenced this pull request Nov 21, 2025
…ite JS to TS) 16 (#8630)

* Initial plan

* Refactor cliparea.jsx to TypeScript with proper prop type validation

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* fix: Context menu remains visible after creating cyclic structure via right-click menu (#8601)

* #7326 - Preview: Delete option is unavailable when right-clicking on a bond in macro mode (#8636)

* fix: Delete option is available when right-clicking on a bond in macro mode

* test: update snapshots

* fix: Selection tool icon open dropdown menu as in Micro mode (#8621)

* #8612 Refactor: Prefer tag over ARIA role (part 4) (#8615)

* Initial plan

* Replace div role="button" with semantic button elements

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* Remove redundant aria-disabled attribute in favor of native disabled

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* f1

* f2

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>
Co-authored-by: Alexey Girin <agirin@mail.ru>

* #8504 Refactor: Variables are missing in props validation (let's rewrite JS to TS) 7 (#8616)

* Initial plan

* Convert TypeChoice.jsx to TypeScript with proper type definitions

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* Add explanatory comments for type compatibility and required props

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* #8619 Refactor: Expected a for-of loop instead of a for loop with this simple iteration (part 4) (#8620)

* Initial plan

* Refactor for loops to for-of loops in utils.js

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* #8563 Refactor: Mark the props of the component as read-only (#8622)

* Initial plan

* Mark component props as read-only using Readonly utility type

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* #8626 Refactor: Variables are missing in props validation (let's rewrite JS to TS) 18 (#8632)

* Initial plan

* Refactor buttonlist.jsx to TypeScript with proper type definitions

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* Fix parameter naming: rename 'multipl' to 'multiple' in oneOrMore function

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* #8627 Refactor: Variables are missing in props validation (let's rewrite JS to TS) 19 (#8633)

* Initial plan

* Convert ComboBox component from JSX to TypeScript with proper prop types

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* Address code review feedback - improve type safety and JSX rendering

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* #8628 Refactor: Variables are missing in props validation (let's rewrite JS to TS) 20 (#8634)

* Initial plan

* Convert errorPopover.jsx to TypeScript with proper type definitions

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* Initial plan

* f1

* f2

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>
Co-authored-by: Kristina <kristina_kasyanovskaya@epam.com>
Co-authored-by: Alexey Girin <agirin@mail.ru>
KukushkinDmi1riy pushed a commit that referenced this pull request Dec 3, 2025
* Initial plan

* Mark component props as read-only using Readonly utility type

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>
KukushkinDmi1riy pushed a commit that referenced this pull request Dec 3, 2025
…ite JS to TS) 16 (#8630)

* Initial plan

* Refactor cliparea.jsx to TypeScript with proper prop type validation

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* fix: Context menu remains visible after creating cyclic structure via right-click menu (#8601)

* #7326 - Preview: Delete option is unavailable when right-clicking on a bond in macro mode (#8636)

* fix: Delete option is available when right-clicking on a bond in macro mode

* test: update snapshots

* fix: Selection tool icon open dropdown menu as in Micro mode (#8621)

* #8612 Refactor: Prefer tag over ARIA role (part 4) (#8615)

* Initial plan

* Replace div role="button" with semantic button elements

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* Remove redundant aria-disabled attribute in favor of native disabled

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* f1

* f2

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>
Co-authored-by: Alexey Girin <agirin@mail.ru>

* #8504 Refactor: Variables are missing in props validation (let's rewrite JS to TS) 7 (#8616)

* Initial plan

* Convert TypeChoice.jsx to TypeScript with proper type definitions

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* Add explanatory comments for type compatibility and required props

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* #8619 Refactor: Expected a for-of loop instead of a for loop with this simple iteration (part 4) (#8620)

* Initial plan

* Refactor for loops to for-of loops in utils.js

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* #8563 Refactor: Mark the props of the component as read-only (#8622)

* Initial plan

* Mark component props as read-only using Readonly utility type

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* #8626 Refactor: Variables are missing in props validation (let's rewrite JS to TS) 18 (#8632)

* Initial plan

* Refactor buttonlist.jsx to TypeScript with proper type definitions

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* Fix parameter naming: rename 'multipl' to 'multiple' in oneOrMore function

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* #8627 Refactor: Variables are missing in props validation (let's rewrite JS to TS) 19 (#8633)

* Initial plan

* Convert ComboBox component from JSX to TypeScript with proper prop types

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* Address code review feedback - improve type safety and JSX rendering

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* #8628 Refactor: Variables are missing in props validation (let's rewrite JS to TS) 20 (#8634)

* Initial plan

* Convert errorPopover.jsx to TypeScript with proper type definitions

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* Initial plan

* f1

* f2

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>
Co-authored-by: Kristina <kristina_kasyanovskaya@epam.com>
Co-authored-by: Alexey Girin <agirin@mail.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Mark the props of the component as read-only

3 participants