Skip to content

Conversation

@stuartbuckell
Copy link

@stuartbuckell stuartbuckell commented Dec 2, 2025

Summary

This PR fixes build and hydration failures when using React 19 with Docusaurus, addressing multiple compatibility issues.

Problems Fixed

1. Redux Context Unavailable During SSR/Hydration

When building with React 19, the static site generation (SSR) and client-side hydration fail with:

TypeError: Cannot read properties of null (reading 'store')
    at useSelector (server.bundle.js:...)

2. Empty oneOf/anyOf Arrays Cause Tab Errors

OpenAPI specs with empty oneOf or anyOf arrays (e.g., "oneOf": []) cause:

Docusaurus error: the <Tabs> component requires at least one <TabItem> children component

Solutions

Redux Hook Wrappers (hooks.ts)

Wrap useTypedDispatch and useTypedSelector with try-catch blocks to gracefully handle cases where the Redux context is unavailable:

  • useTypedDispatch: Returns a no-op function when context is unavailable
  • useTypedSelector: Returns undefined when context is unavailable, then updates via useEffect once the context becomes available

Empty Schema Array Guard (Schema/index.tsx)

Added early return in AnyOneOf component when oneOf/anyOf array is empty or undefined.

SchemaTabs Empty Children Guard (SchemaTabs/index.tsx)

Added guards to handle empty or null children before passing to sanitizeTabsChildren:

  • Filters out null/undefined children before processing
  • Wraps sanitizeTabsChildren in try-catch
  • Returns null if no valid children exist

Related Issues

Testing

Tested with:

  • Docusaurus 3.9.2
  • React 19.2.0
  • docusaurus-theme-openapi-docs 4.5.1

Both npm run build and client-side navigation now work without crashes, including pages with empty oneOf/anyOf schemas.

During server-side rendering and initial hydration with React 19 and
react-redux v7.x, the Redux context is not properly propagated, causing
useSelector and useDispatch to fail with 'Cannot read properties of
null (reading store)'.

This fix wraps useTypedSelector and useTypedDispatch with try-catch
blocks to gracefully handle cases where the Redux context is unavailable:

- useTypedDispatch returns a no-op function when context is unavailable
- useTypedSelector returns undefined when context is unavailable, then
  updates via useEffect once the context becomes available

This is a non-breaking fix that:
- Unblocks React 19 users immediately
- Maintains full functionality when Redux context is available
- Gracefully degrades when context is temporarily unavailable
- Uses minimal code changes in a single file

Fixes PaloAltoNetworks#1130 (partial - addresses SSR/hydration failures)
- Schema/index.tsx: Return null from AnyOneOf when schema array is empty
- SchemaTabs/index.tsx: Guard against empty children before sanitization

This prevents the 'Tabs requires at least one TabItem' error when
OpenAPI specs contain empty oneOf/anyOf arrays (e.g., 'oneOf': []).
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