fix: add SSR guard to MethodEndpoint for React 19 compatibility #1257
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
2. Empty oneOf/anyOf Arrays Cause Tab Errors
OpenAPI specs with empty
oneOforanyOfarrays (e.g.,"oneOf": []) cause:Solutions
Redux Hook Wrappers (
hooks.ts)Wrap
useTypedDispatchanduseTypedSelectorwith try-catch blocks to gracefully handle cases where the Redux context is unavailable:useTypedDispatch: Returns a no-op function when context is unavailableuseTypedSelector: Returnsundefinedwhen context is unavailable, then updates viauseEffectonce the context becomes availableEmpty Schema Array Guard (
Schema/index.tsx)Added early return in
AnyOneOfcomponent whenoneOf/anyOfarray is empty or undefined.SchemaTabs Empty Children Guard (
SchemaTabs/index.tsx)Added guards to handle empty or null children before passing to
sanitizeTabsChildren:sanitizeTabsChildrenin try-catchRelated Issues
Testing
Tested with:
docusaurus-theme-openapi-docs4.5.1Both
npm run buildand client-side navigation now work without crashes, including pages with emptyoneOf/anyOfschemas.