Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jobs:
- name: Run regression test suite
run: npm test

- name: Admin StrictMode tests (React 18)
run: npm run test:admin

- name: Type checks
run: |
npm run test:ts:front
Expand Down Expand Up @@ -81,6 +84,38 @@ jobs:
test -f README.md
test -f LICENSE

react-19:
# Informational: the peer range is React ^18, like the Strapi 5 admin, and stays so. This job
# runs the admin StrictMode tests against React 19 (RFC strapi/strapi#25739) to see problems
# before Strapi moves; a failure here does not block a pull request.
name: Admin StrictMode tests on React 19 (informational)
runs-on: ubuntu-latest
timeout-minutes: 20
continue-on-error: true
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Setup Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '22'
cache: npm

- name: Install dependencies
run: npm ci --legacy-peer-deps

- name: Install React 19 (not saved)
run: npm install --no-save --legacy-peer-deps --ignore-scripts react@19 react-dom@19

- name: Show installed React version
run: node -p "'react ' + require('react/package.json').version + ', react-dom ' + require('react-dom/package.json').version"

- name: Admin StrictMode tests (React 19)
run: npm run test:admin

peer-floor:
# peerDependencies say @strapi/strapi ^5.57.0: prove the lowest supported version, not only
# the acceptance version in the lockfile.
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## [Unreleased]

### Fixed

* Content type names and filter fields load again after a component that started loading them unmounts. The schema cache (`/content-manager/init` and the list view configuration) is shared by the list view toolbar, the bookmark popover, the homepage widget and the bookmark page, but its requests ran on the abort signal of the first component; when that component unmounted (React StrictMode does this once on every mount), every other component got the aborted request and showed raw content type ids or "Fields could not be loaded". The cache now uses a fetch client that is not bound to one component.
* The bookmark dialog no longer logs the Radix "Missing `Description`" warning: its title is its only label (`aria-describedby={undefined}`), as in the Advanced filters dialog since 4.0.3.

### 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.

## [4.0.3](https://github.com/Schero94/Magicmark/compare/v4.0.2...v4.0.3) (2026-11-18)


Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ npm ci --legacy-peer-deps
npm run lint
npm run format:check
npm test
npm run test:admin
npm run test:ts:front
npm run test:ts:back
npm run build
Expand All @@ -427,6 +428,14 @@ view helpers, translation completeness and package rules. CI runs every command
and 24, and type-checks, tests and builds once more against the lowest supported Strapi version
(5.57.0).

`npm run test:admin` renders every admin entry point (the bookmark page, the homepage widget, the
list view toolbar with its popover and filter dialog, the bookmark dialog) inside
`React.StrictMode` with the providers of the Strapi admin, in jsdom with a fake network. It fails
on a mutation sent twice, a read repeated without aborting the first one, an interval, listener,
connection or observer left after unmount, and any console error or warning. A separate CI job
runs the same tests against React 19 for information only: the plugin's peer range is React 18,
like the Strapi 5 admin.

## Contributing and support

- Bugs and feature requests: [open an issue](https://github.com/Schero94/Magicmark/issues/new/choose).
Expand Down
6 changes: 5 additions & 1 deletion admin/src/components/BookmarkFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ export const BookmarkFormModal = ({
return (
<>
<Modal.Root open={open} onOpenChange={handleOpenChange}>
<Modal.Content onKeyDown={keepFocusInside}>
<Modal.Content
onKeyDown={keepFocusInside}
// The title names the dialog; there is no separate description (Radix Dialog opt-out).
aria-describedby={undefined}
>
<Modal.Header closeLabel={formatMessage(msg('form.close', 'Close'))}>
<Modal.Title>{title}</Modal.Title>
</Modal.Header>
Expand Down
7 changes: 3 additions & 4 deletions admin/src/hooks/useOpenBookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* answers with 400, or more than 20 `$and` conditions, which the Content Manager list cannot
* render) is not opened: the user gets a notice that says how to fix it instead of an error.
*/
import { useFetchClient, useNotification } from '@strapi/strapi/admin';
import { useNotification } from '@strapi/strapi/admin';
import { useCallback } from 'react';
import { useIntl } from 'react-intl';
import { useNavigate } from 'react-router-dom';
Expand Down Expand Up @@ -61,7 +61,6 @@ export const normalizeSavedQuery = (
*/
export const useOpenBookmark = () => {
const navigate = useNavigate();
const { get } = useFetchClient();
const { toggleNotification } = useNotification();
const { formatMessage } = useIntl();

Expand Down Expand Up @@ -93,7 +92,7 @@ export const useOpenBookmark = () => {
}
let saved = parsed;
try {
saved = normalizeSavedQuery(parsed, await loadInit(get), location.uid);
saved = normalizeSavedQuery(parsed, await loadInit(), location.uid);
} catch {
// Schemas unavailable: open the bookmark as it was saved.
}
Expand All @@ -105,6 +104,6 @@ export const useOpenBookmark = () => {
}
navigate({ pathname: location.path, search: search ? `?${search}` : '' });
},
[get, navigate, toggleNotification, formatMessage]
[navigate, toggleNotification, formatMessage]
);
};
31 changes: 18 additions & 13 deletions admin/src/hooks/useSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,30 @@
* Every admin who can use the Content Manager may call both, unlike the Content-Type
* Builder API, which needs builder permissions.
*/
import { useAuth, useFetchClient } from '@strapi/strapi/admin';
import { getFetchClient, useAuth } from '@strapi/strapi/admin';
import { useEffect, useMemo, useState } from 'react';
import type { FieldOption } from '../utils/filters';
import { buildFieldOptions, type InitData, type Metadata } from '../utils/fieldOptions';

let initCache: Promise<InitData> | null = null;
const configCache = new Map<string, Promise<Record<string, Metadata>>>();

type Get = ReturnType<typeof useFetchClient>['get'];
/**
* GET for the session-wide caches below. They are shared by every component, so their requests
* must not belong to one component: `useFetchClient` aborts its requests when its component
* unmounts (React StrictMode unmounts once on mount), which would reject the cached promise for
* every other consumer. `getFetchClient()` has no component-bound abort signal.
* @param url - Admin API path.
* @returns The fetch client response.
*/
const sessionGet = <T>(url: string) => getFetchClient().get<T>(url);

/**
* Schemas from `/content-manager/init`, loaded once per admin session.
* @param get - `useFetchClient().get`.
*/
export const loadInit = (get: Get): Promise<InitData> => {
export const loadInit = (): Promise<InitData> => {
if (!initCache) {
initCache = get<{ data: InitData }>('/content-manager/init')
initCache = sessionGet<{ data: InitData }>('/content-manager/init')
.then(({ data }) => data.data)
.catch((error) => {
initCache = null;
Expand All @@ -30,10 +37,10 @@ export const loadInit = (get: Get): Promise<InitData> => {
return initCache;
};

const loadMetadatas = (get: Get, uid: string): Promise<Record<string, Metadata>> => {
const loadMetadatas = (uid: string): Promise<Record<string, Metadata>> => {
let promise = configCache.get(uid);
if (!promise) {
promise = get<{ data: { contentType: { metadatas: Record<string, Metadata> } } }>(
promise = sessionGet<{ data: { contentType: { metadatas: Record<string, Metadata> } } }>(
`/content-manager/content-types/${uid}/configuration`
)
.then(({ data }) => data.data.contentType.metadatas ?? {})
Expand All @@ -51,7 +58,6 @@ const loadMetadatas = (get: Get, uid: string): Promise<Record<string, Metadata>>
* @returns `{ names, isLoading, error }`.
*/
export const useContentTypeNames = () => {
const { get } = useFetchClient();
const [state, setState] = useState<{
names: Map<string, string>;
isLoading: boolean;
Expand All @@ -63,7 +69,7 @@ export const useContentTypeNames = () => {
});
useEffect(() => {
let active = true;
loadInit(get)
loadInit()
.then((init) => {
if (!active) return;
setState({
Expand All @@ -76,7 +82,7 @@ export const useContentTypeNames = () => {
return () => {
active = false;
};
}, [get]);
}, []);
return state;
};

Expand All @@ -86,7 +92,6 @@ export const useContentTypeNames = () => {
* @returns `{ fields, isLoading, error, retry }`.
*/
export const useFilterFields = (uid: string | null) => {
const { get } = useFetchClient();
const permissions = useAuth('MagicMarkFilters', (state) => state.permissions);
const [attempt, setAttempt] = useState(0);
// Results are stored with the request key, so a new uid or a retry shows "loading"
Expand All @@ -110,7 +115,7 @@ export const useFilterFields = (uid: string | null) => {
useEffect(() => {
if (!uid) return undefined;
let active = true;
Promise.all([loadInit(get), loadMetadatas(get, uid)])
Promise.all([loadInit(), loadMetadatas(uid)])
.then(([init, metadatas]) => {
if (active) {
setState({ key, fields: buildFieldOptions(uid, init, metadatas, readable), error: null });
Expand All @@ -120,7 +125,7 @@ export const useFilterFields = (uid: string | null) => {
return () => {
active = false;
};
}, [get, uid, readable, key]);
}, [uid, readable, key]);

const current = state.key === key;
return {
Expand Down
13 changes: 13 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* - Admin panel: browser globals, JSX, React Hooks recommended rules.
* - Server: Node globals, `strapi` as a readonly global.
* - Tests and scripts: Node globals, module type per file extension.
* - Admin StrictMode harness (tests/admin): JSX, Node and browser (jsdom) globals, React Hooks.
* - `eslint-config-prettier` last, so formatting stays with Prettier.
*
* eslint-plugin-jsx-a11y is not used: its latest release (6.10.2) declares
Expand Down Expand Up @@ -81,6 +82,18 @@ export default defineConfig([
globals: { ...globals.node },
},
},
// Admin StrictMode harness and tests: Node test runner with a jsdom window
{
files: ['tests/admin/**/*.{mjs,jsx}'],
extends: [js.configs.recommended, reactHooks.configs.flat.recommended],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: { ecmaFeatures: { jsx: true } },
globals: { ...globals.node, ...globals.browser },
},
rules: { 'no-unused-vars': unusedVars },
},
// Playwright evaluate callbacks run in the browser
{
files: ['scripts/acceptance/**/*.cjs'],
Expand Down
Loading
Loading