Skip to content

fix(admin): keep loads working when a component mounts again - #24

Merged
Schero94 merged 1 commit into
mainfrom
fix/strictmode-remount-loads
Nov 18, 2026
Merged

Schero94 merged 1 commit into
mainfrom
fix/strictmode-remount-loads

Conversation

@Schero94

Copy link
Copy Markdown
Owner

Plan item P2: React StrictMode and React 19 test harness for the admin code.

Bugs found and fixed (each with a regression test that fails before the fix)

useFetchClient (Strapi 5.62) aborts the requests of an unmounted component. In StrictMode (mount, unmount, mount):

  • admin/src/components/OnlineUsersWidget.jsx: the in-flight guard still counted the aborted first load, so the remount skipped its load and the widget stayed on "Online users could not be loaded."
  • admin/src/pages/Analytics.jsx: same guard; in addition the aborted request was treated as a failure. The page showed "Analytics could not be loaded."
  • admin/src/pages/Settings/hooks/useSettingsForm.js: the aborted first load set loadError after the second load had started, so the page stayed on "Settings could not be loaded." although the settings had loaded.

Each load now belongs to one mount (request token / latest request id; the effect cleanup forgets the running load); aborted or outdated loads set no state. Verified by stashing the three fixes: the three regression tests fail, with the fixes all pass.

Harness

tests/admin/harness/* (shared with Magicmark) and tests/admin/strict-mode.test.jsx, run by npm run test:admin. Every entry point is mounted inside <React.StrictMode> with the real Strapi admin providers (same tree as @strapi/admin/dist/admin/admin/tests/utils.mjs Providers), jsdom 31 and a fake network. Assertions: no mutation twice, no non-aborted duplicate GET, nothing left after unmount (intervals, timeouts, listeners, sockets, observers), no console error/warning.

Entry points covered:

  • Plugin page plugins/magic-sessionmanager/*: session dashboard (one live list + stats request, clock and auto-refresh intervals counted while mounted and gone after unmount, details dialog open/close, end-session confirmation open/cancel, debounced search) and admin panel sessions view (list + "View sessions" dialog).
  • Settings: Configuration page (load, every tab), Analytics page.
  • Homepage widget "Online users" (one poll interval while mounted, none after).
  • Content Manager edit view side panel SessionInfoPanel, rendered through Strapi's own DescriptionComponentRenderer inside the admin Form (one live request, Block confirmation open/cancel; nothing for other models).
  • Initializer and plugin registration (menu link, two settings links, widget, side panel).

React 19

  • Local: npm install --no-save --legacy-peer-deps --ignore-scripts react@19 react-dom@19 (19.3.1): 11/11 pass.
  • CI: new react-19 job, informational (continue-on-error: true). The React peer range stays ^18.0.0 (not widened), like the Strapi 5 admin.

Other changes

  • devDependency jsdom@^31.0.1 (31.0.1 published 2026-11-13, maintained); esbuild was already a devDependency.
  • ESLint block for tests/admin/**/*.{mjs,jsx}; README "Development and tests"; CHANGELOG [Unreleased].
  • Generic harness changes compared with Magicmark: CJS interop wrapper default export follows __esModule (needed for import styled from 'styled-components'), and checkStrictEntry unmounts when whileMounted throws.

Gate (local, Node 22.23.1)

npm run lint, npm run format:check, npm test (864 pass), npm run test:admin (11 pass), npm run test:ts:front, npm run test:ts:back, npm run build, npm run verify, npm run verify:runtime, npm pack --dry-run (34 files, no tests or sources).

Docs read

🤖 Generated with Claude Code

useFetchClient (Strapi 5.62) aborts the requests of an unmounted component.
The Online users widget and the Analytics page then skipped their next load
because the aborted one still counted as running, and the Configuration page
set the error of the aborted load after the next load had started. Under
React.StrictMode (mount, unmount, mount) all three showed "could not be
loaded". Each load now belongs to one mount; aborted or outdated loads set no
state.

Adds the admin StrictMode harness (tests/admin, npm run test:admin): every
admin entry point mounted in React.StrictMode with the real Strapi admin
providers in jsdom, fake network, counting of requests, timers, listeners,
connections, observers and console output. CI runs it on React 18 and, for
information only, on React 19.

Docs read: react.dev/reference/react/StrictMode, react.dev/blog/2024/04/25/
react-19-upgrade-guide, @strapi/admin 5.62 useFetchClient.mjs,
getFetchClient.mjs, DescriptionComponentRenderer.mjs and tests/utils.mjs
(Providers), jsdom 31 README, Node 22 module customization hooks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Schero94
Schero94 merged commit 4a18a47 into main Nov 18, 2026
8 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 18, 2026
## [4.14.2](v4.14.1...v4.14.2) (2026-11-18)

### Bug Fixes

* **admin:** keep loads working when a component mounts again ([#24](#24)) ([4a18a47](4a18a47))

### Fixed

* The Online users widget, the Analytics page and the Configuration page no longer show "could not be loaded" after the component is mounted a second time. `useFetchClient` aborts the requests of an unmounted component; the widget and the Analytics page then skipped their next load because the aborted one still counted as running, and the Configuration page set the error of the aborted load after the next load had started. React StrictMode mounts every component twice in development, and React 19 and a future StrictMode admin do the same. Each load now belongs to one mount: an aborted or outdated load sets no state.

### Tests

* `npm run test:admin`: StrictMode tests for every admin entry point (no duplicate requests, no leaked timers, listeners, connections or observers after unmount, no console errors or warnings), also run against React 19 in an informational CI job.
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