Skip to content

fix: rollback scalar #2454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 6, 2024
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
6 changes: 6 additions & 0 deletions .changeset/quiet-doors-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@gitbook/react-openapi': minor
'gitbook': patch
---

Rollback of scalar modal while fixing perf issue
Binary file modified bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
},
"patchedDependencies": {
"@vercel/next@4.3.6": "patches/@vercel%2Fnext@4.3.6.patch"
},
"dependencies": {
"@scalar/api-client-react": "0.3.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function OpenAPI(props: BlockProps<DocumentBlockSwagger>) {

async function OpenAPIBody(props: BlockProps<DocumentBlockSwagger>) {
const { block, context } = props;
const { data, specUrl, error } = await fetchOpenAPIBlock(block, context.resolveContentRef);
const { data, error } = await fetchOpenAPIBlock(block, context.resolveContentRef);

if (error) {
return (
Expand All @@ -41,7 +41,7 @@ async function OpenAPIBody(props: BlockProps<DocumentBlockSwagger>) {
);
}

if (!data || !specUrl) {
if (!data) {
return null;
}

Expand All @@ -55,7 +55,6 @@ async function OpenAPIBody(props: BlockProps<DocumentBlockSwagger>) {
},
CodeBlock: PlainCodeBlock,
defaultInteractiveOpened: context.mode === 'print',
specUrl,
id: block.meta?.id,
}}
className="openapi-block"
Expand Down
52 changes: 23 additions & 29 deletions packages/gitbook/src/components/DocumentView/OpenAPI/scalar.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
@import '@scalar/api-client-react/style.css';

.light .scalar-modal-layout,
.light .scalar-app,
.light .scalar {
--scalar-color-1: color-mix(
in srgb,
Expand Down Expand Up @@ -53,13 +50,8 @@
--scalar-button-1: rgb(49 53 56);
--scalar-button-1-color: #fff;
--scalar-button-1-hover: rgb(28 31 33);

--scalar-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.11);
--scalar-shadow-2: rgba(0, 0, 0, 0.08) 0px 13px 20px 0px, rgba(0, 0, 0, 0.08) 0px 3px 8px 0px,
#eeeeed 0px 0 0 1px;
}
.dark .scalar-modal-layout,
.dark .scalar-app,
.dark .scalar {
--scalar-color-1: color-mix(
in srgb,
Expand Down Expand Up @@ -110,13 +102,8 @@
--scalar-button-1: #f6f6f6;
--scalar-button-1-color: #000;
--scalar-button-1-hover: #e7e7e7;

--scalar-shadow-1: 0 1px 3px 0 rgb(0, 0, 0, 0.1);
--scalar-shadow-2: rgba(15, 15, 15, 0.2) 0px 3px 6px, rgba(15, 15, 15, 0.4) 0px 9px 24px,
0 0 0 1px rgba(255, 255, 255, 0.1);
}
.scalar-modal-layout,
.scalar-app,
.scalar {
--scalar-font: initial;
--scalar-font-code: var(--font-mono);
Expand Down Expand Up @@ -178,7 +165,7 @@
.scalar-api-client__close:hover {
cursor: pointer;
}
.scalar .scalar-app-layout {
.scalar .scalar-app {
background: var(--scalar-background-3);
height: calc(100dvh - 100px);
max-width: 1280px;
Expand Down Expand Up @@ -215,6 +202,23 @@
cursor: pointer;
animation: scalardrawerexitfadein 0.35s forwards;
}
.scalar .scalar-app-exit:before {
content: '\00d7';
font-family: sans-serif;
position: absolute;
top: 0;
right: 0;
font-size: 30px;
font-weight: 100;
line-height: 50px;
right: 12px;
text-align: center;
color: white;
opacity: 0.6;
}
.scalar .scalar-app-exit:hover:before {
opacity: 1;
}
@keyframes scalardrawerexitfadein {
from {
opacity: 0;
Expand Down Expand Up @@ -301,6 +305,11 @@
scrollbar-width: thin;
-webkit-overflow-scrolling: touch;
}
@supports (-moz-appearance: none) {
.scalar .custom-scroll {
padding-right: 12px;
}
}
.scalar .custom-scroll:hover {
scrollbar-color: rgba(0, 0, 0, 0.24) transparent;
}
Expand Down Expand Up @@ -338,18 +347,3 @@
padding-right: 12px;
}
}
.dark .scalar .client-wrapper-bg-color {
background: linear-gradient(
color-mix(in srgb, var(--tw-bg-base) 6%, transparent) 1%,
color-mix(in srgb, var(--scalar-background-1) 30%, black) 9%
);
}
.light .scalar .client-wrapper-bg-color {
background-color: var(--scalar-background-2) !important;
}
.scalar .gitbook-show {
display: block !important;
}
.scalar .gitbook-hidden {
display: none !important;
}
8 changes: 4 additions & 4 deletions packages/gitbook/src/lib/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export async function fetchOpenAPIBlock(
block: DocumentBlockSwagger,
resolveContentRef: (ref: ContentRef) => Promise<ResolvedContentRef | null>,
): Promise<
| { data: OpenAPIOperationData | null; specUrl: string | null; error?: undefined }
| { error: OpenAPIFetchError; data?: undefined; specUrl?: undefined }
| { data: OpenAPIOperationData | null; error?: undefined }
| { error: OpenAPIFetchError; data?: undefined }
> {
const resolved = block.data.ref ? await resolveContentRef(block.data.ref) : null;
if (!resolved || !block.data.path || !block.data.method) {
return { data: null, specUrl: null };
return { data: null };
}

try {
Expand All @@ -37,7 +37,7 @@ export async function fetchOpenAPIBlock(
fetcher,
);

return { data, specUrl: resolved.href };
return { data };
} catch (error) {
if (error instanceof OpenAPIFetchError) {
return { error };
Expand Down
3 changes: 2 additions & 1 deletion packages/react-openapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"version": "0.6.0",
"dependencies": {
"@scalar/api-client-react": "1.0.20",
"@scalar/api-client-react": "0.3.7",
"@scalar/oas-utils": "0.1.6",
"classnames": "^2.5.1",
"flatted": "^3.2.9",
"openapi-types": "^12.1.3",
Expand Down
9 changes: 7 additions & 2 deletions packages/react-openapi/src/OpenAPICodeSample.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

import { CodeSampleInput, codeSampleGenerators } from './code-samples';
import { OpenAPIOperationData } from './fetchOpenAPIOperation';
import { OpenAPIOperationData, toJSON } from './fetchOpenAPIOperation';
import { generateMediaTypeExample } from './generateSchemaExample';
import { InteractiveSection } from './InteractiveSection';
import { getServersURL } from './OpenAPIServerURL';
Expand Down Expand Up @@ -70,14 +70,19 @@ export function OpenAPICodeSample(props: {
return null;
}

async function fetchOperationData() {
'use server';
return toJSON(data);
}

return (
<InteractiveSection
header="Request"
className="openapi-codesample"
tabs={samples}
overlay={
data['x-hideTryItPanel'] || data.operation['x-hideTryItPanel'] ? null : (
<ScalarApiButton />
<ScalarApiButton fetchOperationData={fetchOperationData} />
)
}
/>
Expand Down
10 changes: 3 additions & 7 deletions packages/react-openapi/src/OpenAPIOperation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { OpenAPIResponseExample } from './OpenAPIResponseExample';
import { OpenAPIServerURL } from './OpenAPIServerURL';
import { OpenAPISpec } from './OpenAPISpec';
import { OpenAPIClientContext, OpenAPIContextProps } from './types';
import { ApiClientModalProvider } from '@scalar/api-client-react';
import { ScalarApiClient } from './ScalarApiButton';

/**
* Display an interactive OpenAPI operation.
Expand All @@ -23,15 +23,11 @@ export function OpenAPIOperation(props: {

const clientContext: OpenAPIClientContext = {
defaultInteractiveOpened: context.defaultInteractiveOpened,
specUrl: context.specUrl,
icons: context.icons,
};

return (
<ApiClientModalProvider
configuration={{ spec: { url: context.specUrl } }}
initialRequest={{ path: data.path, method: data.method }}
>
<ScalarApiClient>
<div className={classNames('openapi-operation', className)}>
<div className="openapi-intro">
<h2 className="openapi-summary" id={context.id}>
Expand Down Expand Up @@ -67,6 +63,6 @@ export function OpenAPIOperation(props: {
</div>
</div>
</div>
</ApiClientModalProvider>
</ScalarApiClient>
);
}
Loading
Loading