Skip to content

fix: correct frontend effect dependency arrays - #1709

Draft
shivoomiess wants to merge 1 commit into
build/frontend-react-19from
fix/frontend-effect-dependencies
Draft

fix: correct frontend effect dependency arrays#1709
shivoomiess wants to merge 1 commit into
build/frontend-react-19from
fix/frontend-effect-dependencies

Conversation

@shivoomiess

@shivoomiess shivoomiess commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR corrects the effect dependency arrays in several frontend components to ensure the correct functioning and optimized rendering of components.

Motivation and Context

These changes are required to maintain the correct functionality and prevent unnecessary re-rendering of components in the frontend, which may lead to improved performance and prevent potential bugs.

Changes

  1. Introduced new local variables for dependencies used in useEffect hooks to ensure that the correct dependencies are tracked.
  2. Replaced useEffect dependencies with the newly introduced local variables.
  3. Replaced useEffect in QuestionaryComponentInstrumentPicker with useCallback to create a memoized version of the function, preventing unnecessary re-rendering.
  4. Updated dependencies in all affected hooks to ensure correct functioning and optimized rendering.

Note: These changes have been made across multiple files including ChangeProposalStatus.tsx, QuestionaryComponentInstrumentPicker.tsx, ReviewSummary.tsx, TechnicalReviewSummary.tsx, ShipmentContainer.tsx and several others.

How Has This Been Tested?

Fixes Jira Issue

https://jira.ess.eu//browse/

Depends On

Tests included/Docs Updated?

  • I have added tests to cover my changes.
  • All relevant doc has been updated

@shivoomiess shivoomiess changed the title fix(frontend): correct 13 effect dependency arrays fix: correct frontend effect dependency arrays Aug 5, 2026
@shivoomiess shivoomiess closed this Aug 5, 2026
@shivoomiess shivoomiess reopened this Aug 5, 2026
@shivoomiess
shivoomiess force-pushed the fix/frontend-effect-dependencies branch from 5730ab7 to 1d10bde Compare August 6, 2026 08:47
@shivoomiess
shivoomiess force-pushed the fix/frontend-effect-dependencies branch from 1d10bde to 7b49d42 Compare August 6, 2026 09:20
@shivoomiess
shivoomiess force-pushed the fix/frontend-effect-dependencies branch from 7b49d42 to 49be444 Compare August 6, 2026 11:41
`react-hooks/exhaustive-deps` reported 18 warnings. 13 of them are independent of
the table stack and are fixed here; the other 5 are left for the material-table
migration to absorb (see below).

Every missing dependency in the seven data hooks is a query parameter that the
effect reads but never re-runs for, so the hook returns data for whatever
argument it happened to receive first:

- `useEventsData`, `useStatusesData`, `useWorkflowsData` - `entityType`
- `useFapProposalsData` - `legacy`
- `useVisitRegistration` - `userId`
- `useUserExperiments` - `notDraft`, `onlyUpcoming`, `instrumentId`
- `useStatusActionsData` - `isPregeneratedProposalPdfsEnabled`

None of these can loop. `api` comes from `useDataApi`, which returns a
`useCallback`, and every added dependency is a primitive - a string enum, a
number, or a boolean.

The `useStatusActionsData` one is a real bug rather than a latent risk. The flag
comes from `FeatureContext` and decides whether `PROPOSALDOWNLOAD` is filtered
out of the result. Because it was not a dependency, the filter used whatever the
flag was when the effect first ran; if the feature context resolved after that
first fetch, the action list was wrong until something else forced a refetch.

The rest are structural, with no behaviour change:

- `ChangeProposalStatus` passed `selectedProposalsWorkflowIds[0]` directly in the
  array, which the rule cannot statically verify. Extracted to
  `primaryWorkflowId` and used in both places.
- `ShipmentContainer` referenced `props.onDirtyStateChange`, so the rule wanted
  the whole `props` object - which changes every render. Destructured the
  callback instead; the dependency value is identical, just checkable.
- `ReviewSummary` and `TechnicalReviewSummary` depended on `api` while their
  effects had stopped calling it, and were missing
  `<review>.proposal?.callId`, which the rule cannot track through an optional
  chain. Extracted to `callId` and dropped the dead `api` dependency.
- `QuestionaryComponentInstrumentPicker` needed `getValueWithInstrumentName`,
  which was rebuilt on every render. Wrapped in `useCallback` keyed on `value`
  and `config`. Both are read off `answer`, which the effect already depends on,
  so the effect cannot run more often than it does today - if `answer` were
  unstable this component would already be looping, because it already calls
  `setRequestTimeForInstrument` on every run.

Deferred - all 5 sit on @material-table/core internals and will be rewritten or
deleted by the v8 migration, so fixing them now would only create conflicts:
`useExpandCollapseAll` (reaches into `dataManager.sortedData`, `props.detailPanel`
and scrapes `thead tr` from the DOM), `ProposalTableInstrumentScientist` (drives
`tableData.checked`) and `FapInstrumentProposalsTable`.

`tsc --noEmit`, `eslint` and `vite build` pass. Not exercised at runtime.
@shivoomiess
shivoomiess force-pushed the fix/frontend-effect-dependencies branch from 49be444 to 5a61e8f Compare August 10, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant