unbridled-41 opened a new pull request, #4331:
URL: https://github.com/apache/rocketmq-dashboard/pull/4331
Follow-up implementing the extraction @lizhimins asked for on #4166: instead
of adding a fourth hand-rolled request-id ref, one shared helper now covers
every async flow in the page, including the previously unguarded broker config
preview. The display-only race itself is documented there; the preview never
feeds the write path (`handleConfigSubmit` rebuilds the request from form
values), so this change only unifies the invalidation mechanism.
## What changed
`web/src/pages/cluster/index.tsx` had six hand-written latest-request guards
(`nsRegistryRequestRef`, `registryClustersRequestRef`, `k8sCertsRequestRef`,
`nsConfigDiffRequestRef`, `brokerConfigDiffRequestRef`,
`connectionTestRequestRef`) — each a monotonic counter ref compared after
`await` and bumped at close/unmount. The broker config preview
(`handleConfigPreview`) had no guard at all.
This PR introduces one shared helper and converts every flow to it:
- `createRequestGeneration()` returns `{ begin, isCurrent, invalidate }`;
`useRequestGeneration()` creates one stable generation per async flow (lazy
`useState` initializer, no ref access during render).
- All six existing refs are replaced by the helper — same
begin/check/invalidate points, so existing behavior is unchanged; the guards'
dep arrays list the stable generation objects to keep
`react-hooks/exhaustive-deps` clean.
- The config preview gains the same guard: `begin()` when the request is
issued, `isCurrent()` before committing the panel/toast and before clearing the
loading state, and `invalidate()` at the three points where the preview is
already discarded today — dialog open (`handleConfigOpen`), dialog cancel, and
any form value change (`onValuesChange`, which now also resets the preview
loading state alongside clearing the panel).
A superseded preview response (cancel/reopen while in flight, or an edit
while in flight) can therefore no longer overwrite the panel, fire its toast,
or clobber a newer request's loading state.
## Tests
One regression covering the maintainer-identified residual window (cancel
and reopen while a preview is in flight):
- `keeps the latest broker config preview after a superseded response
finishes last`: preview A is held in flight, the dialog is cancelled and
reopened, the form changes, preview B is issued and resolved, then A resolves
last — the panel must keep B (`defaultTopicQueueNums=24`) and never show A
(`defaultTopicQueueNums=16`).
- Red on unmodified base `25132a0d` (fix stashed): `1 failed | 25 passed` —
the stale response overwrote the newer preview.
- Green with the fix: `npx vitest run
src/pages/cluster/__tests__/ClusterPage.test.tsx` → `Test Files 1 passed (1)`,
`Tests 26 passed (26)`.
- Full web suite: `981-982 passed` with 1-3 per-run failures in varying
files (`MetricsExplorer`, `ClusterPage` nameserver registry create/delete,
`ConsumerPage` group health) — those three files all pass in isolation with the
fix applied (`82 passed (82)`), matching the documented full-suite
parallel-load flakiness; the ClusterPage isolation run is also red on base
exactly for the new test (`1 failed | 25 passed`), attributing the full-suite
flake to load, not the change.
- `eslint` clean on both changed files (also enforced by the pre-commit
`lint-staged` hook), `tsc --noEmit` clean, `vite build` succeeds (`✓ built in
8.40s`).
## Risk
Low. The helper is a mechanical generalization of the ref pattern already
used in this file, with the invalidation points unchanged; the only new
behavior is the intended one — superseded preview responses no longer commit
state, toast, or touch loading. No API, data, or visual changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]