Skip to content

fix(sonar): performance — 1 issue - #225

Open
huandrey wants to merge 3 commits into
mainfrom
fix/sonar-performance-20260902120426
Open

huandrey wants to merge 3 commits into
mainfrom
fix/sonar-performance-20260902120426

Conversation

@huandrey

@huandrey huandrey commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

SonarQube auto-fix — performance

Generated by sonar-autofix. Each commit resolves one issue.
All fixes were independently reviewed by a judge-agent before being committed.

Rule File Line Issue
javascript:S6481 react/ModalState.js 521 The object passed as the value prop to the Context provider changes every render.

Skipped in this group: 0 issues

Note: react/ModalState.js is a root/public component per AGENTS.md and requires human approval before merge.

render() built a fresh 19-key object literal for the ModalStateContext
provider on every render, forcing every consumer to re-render even when
nothing it reads had changed.

Uses the house react/utils/memoizeOne.js helper, same pattern already
established for the geolocation context. The memoized factory takes the
same 19 state/prop values as positional args (the class-property arrow
handlers are read from this, stable for the instance's lifetime), so a
shallow positional compare is sound.

File: react/ModalState.js:521
Rule: javascript:S6481
@huandrey
huandrey requested a review from a team as a code owner September 2, 2026 15:06
@vtex-io-ci-cd

vtex-io-ci-cd Bot commented Sep 2, 2026

Copy link
Copy Markdown

Hi! I'm VTEX IO CI/CD Bot and I'll be helping you to publish your app! 🤖

Please select which version do you want to release:

  • Patch (backwards-compatible bug fixes)

  • Minor (backwards-compatible functionality)

  • Major (incompatible API changes)

And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.

  • No thanks, I would rather do it manually 😞

@vtex-pr-sentinel

Copy link
Copy Markdown

🛡️ SDD Check — action required

I couldn't detect an SDD in this PR. Please check one option below (requires write access to the repo):

  • SDD lives in another PR — paste the SDD PR URL here:
  • This PR doesn't need an SDD
  • SDD applies, but I'm not adopting it in this PR

@huandrey huandrey added the sonar label Sep 2, 2026
@huandrey huandrey self-assigned this Sep 2, 2026
Comment thread react/ModalState.js
shouldSearchArea,
showOtherPickupPoints
) => ({
activeState,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

acho que vale tentar ignorar essa regra do sonar nesse bloco de código, oq acha @huandrey ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Concordo, @jeffersontuc. Segui com a supressão em bf8c7a7: /* NOSONAR javascript:S107 */ na linha do =>, que é onde o Sonar ancora o S107, mais um comentário acima do getContextValue explicando o motivo. O memoizeOne compara os argumentos por identidade, então agrupar tudo num objeto quebraria a memoização.

Considerei a alternativa de memoizar em cima de this.state (um parâmetro só, sem supressão), mas ela reconstruiria o value em qualquer setState, inclusive de campos que nem estão no contexto (askForGeolocation, localSearching). Preferi manter a memoização precisa.

Detalhe: usei comentário de bloco porque o Prettier move um // NOSONAR de fim de linha para dentro do objeto, e aí a supressão para de valer.

…d context builder

One positional argument per context field is deliberate: memoizeOne
compares arguments by identity, so grouping them into an object would
defeat the memoization. A block comment keeps the NOSONAR on the arrow
line where Sonar anchors the issue (Prettier moves a trailing // comment
into the object body).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QdDDu2mUJJfM3vfG227Uqr
@sonar-workflows

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants