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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React from "react";

import BrowserOnly from "@docusaurus/BrowserOnly";
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
import { useTypedSelector } from "@theme/ApiItem/hooks";

function colorForMethod(method: string) {
Expand Down Expand Up @@ -38,6 +39,26 @@ export interface Props {
}

function MethodEndpoint({ method, path, context }: Props) {
// During SSR, render without Redux store access to avoid "Cannot read properties
// of null (reading 'store')" errors caused by useSelector running outside a Provider.
if (!ExecutionEnvironment.canUseDOM) {
return (
<>
<pre className="openapi__method-endpoint">
<span className={"badge badge--" + colorForMethod(method)}>
{method === "event" ? "Webhook" : method.toUpperCase()}
</span>{" "}
{method !== "event" && (
<h2 className="openapi__method-endpoint-path">
{`${path.replace(/{([a-z0-9-_]+)}/gi, ":$1")}`}
</h2>
)}
</pre>
<div className="openapi__divider" />
</>
);
}

let serverValue = useTypedSelector((state: any) => state.server.value);
let serverUrlWithVariables = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ const AnyOneOf: React.FC<SchemaProps> = ({
schemaPath,
}) => {
const key = schema.oneOf ? "oneOf" : "anyOf";
const schemaArray = schema[key];

// Empty oneOf/anyOf arrays are valid in OpenAPI specs but would cause the
// Tabs component to throw "requires at least one TabItem". Return null instead.
if (!schemaArray || !Array.isArray(schemaArray) || schemaArray.length === 0) {
return null;
}

const type = schema.oneOf
? translate({ id: OPENAPI_SCHEMA_ITEM.ONE_OF, message: "oneOf" })
: translate({ id: OPENAPI_SCHEMA_ITEM.ANY_OF, message: "anyOf" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,43 @@ function TabsComponent(props: SchemaTabsProps): React.JSX.Element {
</div>
);
}
export default function SchemaTabs(props: SchemaTabsProps): React.JSX.Element {
export default function SchemaTabs(
props: SchemaTabsProps
): React.JSX.Element | null {
const isBrowser = useIsBrowser();

const children = Array.isArray(props.children)
? props.children.filter(Boolean)
: props.children
? [props.children]
: [];

if (children.length === 0) {
return null;
}

let sanitizedChildren;
try {
sanitizedChildren = sanitizeTabsChildren(children);
} catch {
return null;
}

if (
!sanitizedChildren ||
(Array.isArray(sanitizedChildren) && sanitizedChildren.length === 0)
) {
return null;
}

return (
<TabsComponent
// Remount tabs after hydration
// Temporary fix for https://github.com/facebook/docusaurus/issues/5653
key={String(isBrowser)}
{...props}
>
{sanitizeTabsChildren(props.children)}
{sanitizedChildren}
</TabsComponent>
);
}
Loading