Skip to content

Admin ContentListPage can trigger React hook-order error #300 #439

@huckabarry

Description

@huckabarry

Description

The admin content list route currently has a hook-order bug in ContentListPage that can trigger React error #300:

Minified React error #300
Rendered fewer hooks than expected

I hit this on the admin Posts page while navigating/clicking quickly in the dashboard.

Root cause

In packages/admin/src/router.tsx, ContentListPage defines React.useMemo(...) after early returns for:

  • if (!manifest) return <LoadingScreen />
  • if (!collectionConfig) return <NotFoundPage ... />
  • if (error) return <ErrorScreen ... />

That means some renders execute fewer hooks than others, which violates React's hook rules.

Relevant source

packages/admin/src/router.tsx

The current shape on main still looks like this:

if (!manifest) {
  return <LoadingScreen />;
}

const collectionConfig = manifest.collections[collection];

if (!collectionConfig) {
  return <NotFoundPage ... />;
}

if (error) {
  return <ErrorScreen ... />;
}

const items = React.useMemo(() => {
  return data?.pages.flatMap((page) => page.items) || [];
}, [data]);

Suggested fix

Move the useMemo call above any early returns, or compute items without a hook.

For example:

const items = React.useMemo(() => {
  return data?.pages.flatMap((page) => page.items) || [];
}, [data]);

if (!manifest) return <LoadingScreen />;
// ...

Environment

  • @emdash-cms/admin: 0.1.1
  • also visible in upstream main as of 2026-04-10

Notes

I fixed this locally by moving the hook above the early returns, and the React #300 error stopped occurring on the content list route.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions