Use content-visibility on open api operations (#2451)

This commit is contained in:
Brett Jephson
2024-09-05 17:21:42 +01:00
committed by GitHub
parent af9e66e87e
commit 51fa3ab2c8
5 changed files with 15 additions and 6 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@gitbook/react-openapi': patch
'gitbook': patch
---
Adds content-visibility css property to OpenAPI Operation for better render performance
@@ -20,11 +20,6 @@ export async function OpenAPI(props: BlockProps<DocumentBlockSwagger>) {
const { block, style } = props;
return (
<div className={tcls('w-full', 'flex', 'flex-row', style, 'max-w-full')}>
{/*
Invisible span with the ID to correctly identify the active section in the aside navigation.
We don't use the full <div> because it can be longer than the viewport and will not work well with IntersectionObserver.
*/}
<span id={block.meta?.id} />
<React.Suspense fallback={<OpenAPIFallback />}>
<OpenAPIBody {...props} />
</React.Suspense>
@@ -61,6 +56,7 @@ async function OpenAPIBody(props: BlockProps<DocumentBlockSwagger>) {
CodeBlock: PlainCodeBlock,
defaultInteractiveOpened: context.mode === 'print',
specUrl,
id: block.meta?.id,
}}
className="openapi-block"
/>
@@ -1,4 +1,6 @@
.openapi-operation {
content-visibility: auto;
contain-intrinsic-height: 600px;
@apply flex-1 flex flex-col gap-6;
}
@@ -34,7 +34,9 @@ export function OpenAPIOperation(props: {
>
<div className={classNames('openapi-operation', className)}>
<div className="openapi-intro">
<h2 className="openapi-summary">{operation.summary}</h2>
<h2 className="openapi-summary" id={context.id}>
{operation.summary}
</h2>
{operation.description ? (
<Markdown className="openapi-description" source={operation.description} />
) : null}
+3
View File
@@ -18,6 +18,9 @@ export interface OpenAPIClientContext {
* @default false
*/
defaultInteractiveOpened?: boolean;
/** Optional id attached to the OpenAPI Operation heading and used as an anchor */
id?: string;
}
export interface OpenAPIFetcher {