Skip to content

Commit 4cbcc5b

Browse files
fix: rollback scalar (#2454)
Co-authored-by: Brett Jephson <brett@gitbook.io>
1 parent 51955da commit 4cbcc5b

File tree

11 files changed

+190
-54
lines changed

11 files changed

+190
-54
lines changed

.changeset/quiet-doors-double.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@gitbook/react-openapi': minor
3+
'gitbook': patch
4+
---
5+
6+
Rollback of scalar modal while fixing perf issue

bun.lockb

-4.15 KB
Binary file not shown.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@
2828
},
2929
"patchedDependencies": {
3030
"@vercel/next@4.3.6": "patches/@vercel%2Fnext@4.3.6.patch"
31+
},
32+
"dependencies": {
33+
"@scalar/api-client-react": "0.3.7"
3134
}
3235
}

packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPI.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export async function OpenAPI(props: BlockProps<DocumentBlockSwagger>) {
2929

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

3434
if (error) {
3535
return (
@@ -41,7 +41,7 @@ async function OpenAPIBody(props: BlockProps<DocumentBlockSwagger>) {
4141
);
4242
}
4343

44-
if (!data || !specUrl) {
44+
if (!data) {
4545
return null;
4646
}
4747

@@ -55,7 +55,6 @@ async function OpenAPIBody(props: BlockProps<DocumentBlockSwagger>) {
5555
},
5656
CodeBlock: PlainCodeBlock,
5757
defaultInteractiveOpened: context.mode === 'print',
58-
specUrl,
5958
id: block.meta?.id,
6059
}}
6160
className="openapi-block"

packages/gitbook/src/components/DocumentView/OpenAPI/scalar.css

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
@import '@scalar/api-client-react/style.css';
2-
31
.light .scalar-modal-layout,
4-
.light .scalar-app,
52
.light .scalar {
63
--scalar-color-1: color-mix(
74
in srgb,
@@ -53,13 +50,8 @@
5350
--scalar-button-1: rgb(49 53 56);
5451
--scalar-button-1-color: #fff;
5552
--scalar-button-1-hover: rgb(28 31 33);
56-
57-
--scalar-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.11);
58-
--scalar-shadow-2: rgba(0, 0, 0, 0.08) 0px 13px 20px 0px, rgba(0, 0, 0, 0.08) 0px 3px 8px 0px,
59-
#eeeeed 0px 0 0 1px;
6053
}
6154
.dark .scalar-modal-layout,
62-
.dark .scalar-app,
6355
.dark .scalar {
6456
--scalar-color-1: color-mix(
6557
in srgb,
@@ -110,13 +102,8 @@
110102
--scalar-button-1: #f6f6f6;
111103
--scalar-button-1-color: #000;
112104
--scalar-button-1-hover: #e7e7e7;
113-
114-
--scalar-shadow-1: 0 1px 3px 0 rgb(0, 0, 0, 0.1);
115-
--scalar-shadow-2: rgba(15, 15, 15, 0.2) 0px 3px 6px, rgba(15, 15, 15, 0.4) 0px 9px 24px,
116-
0 0 0 1px rgba(255, 255, 255, 0.1);
117105
}
118106
.scalar-modal-layout,
119-
.scalar-app,
120107
.scalar {
121108
--scalar-font: initial;
122109
--scalar-font-code: var(--font-mono);
@@ -178,7 +165,7 @@
178165
.scalar-api-client__close:hover {
179166
cursor: pointer;
180167
}
181-
.scalar .scalar-app-layout {
168+
.scalar .scalar-app {
182169
background: var(--scalar-background-3);
183170
height: calc(100dvh - 100px);
184171
max-width: 1280px;
@@ -215,6 +202,23 @@
215202
cursor: pointer;
216203
animation: scalardrawerexitfadein 0.35s forwards;
217204
}
205+
.scalar .scalar-app-exit:before {
206+
content: '\00d7';
207+
font-family: sans-serif;
208+
position: absolute;
209+
top: 0;
210+
right: 0;
211+
font-size: 30px;
212+
font-weight: 100;
213+
line-height: 50px;
214+
right: 12px;
215+
text-align: center;
216+
color: white;
217+
opacity: 0.6;
218+
}
219+
.scalar .scalar-app-exit:hover:before {
220+
opacity: 1;
221+
}
218222
@keyframes scalardrawerexitfadein {
219223
from {
220224
opacity: 0;
@@ -301,6 +305,11 @@
301305
scrollbar-width: thin;
302306
-webkit-overflow-scrolling: touch;
303307
}
308+
@supports (-moz-appearance: none) {
309+
.scalar .custom-scroll {
310+
padding-right: 12px;
311+
}
312+
}
304313
.scalar .custom-scroll:hover {
305314
scrollbar-color: rgba(0, 0, 0, 0.24) transparent;
306315
}
@@ -338,18 +347,3 @@
338347
padding-right: 12px;
339348
}
340349
}
341-
.dark .scalar .client-wrapper-bg-color {
342-
background: linear-gradient(
343-
color-mix(in srgb, var(--tw-bg-base) 6%, transparent) 1%,
344-
color-mix(in srgb, var(--scalar-background-1) 30%, black) 9%
345-
);
346-
}
347-
.light .scalar .client-wrapper-bg-color {
348-
background-color: var(--scalar-background-2) !important;
349-
}
350-
.scalar .gitbook-show {
351-
display: block !important;
352-
}
353-
.scalar .gitbook-hidden {
354-
display: none !important;
355-
}

packages/gitbook/src/lib/openapi.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ export async function fetchOpenAPIBlock(
1919
block: DocumentBlockSwagger,
2020
resolveContentRef: (ref: ContentRef) => Promise<ResolvedContentRef | null>,
2121
): Promise<
22-
| { data: OpenAPIOperationData | null; specUrl: string | null; error?: undefined }
23-
| { error: OpenAPIFetchError; data?: undefined; specUrl?: undefined }
22+
| { data: OpenAPIOperationData | null; error?: undefined }
23+
| { error: OpenAPIFetchError; data?: undefined }
2424
> {
2525
const resolved = block.data.ref ? await resolveContentRef(block.data.ref) : null;
2626
if (!resolved || !block.data.path || !block.data.method) {
27-
return { data: null, specUrl: null };
27+
return { data: null };
2828
}
2929

3030
try {
@@ -37,7 +37,7 @@ export async function fetchOpenAPIBlock(
3737
fetcher,
3838
);
3939

40-
return { data, specUrl: resolved.href };
40+
return { data };
4141
} catch (error) {
4242
if (error instanceof OpenAPIFetchError) {
4343
return { error };

packages/react-openapi/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
},
1111
"version": "0.6.0",
1212
"dependencies": {
13-
"@scalar/api-client-react": "1.0.20",
13+
"@scalar/api-client-react": "0.3.7",
14+
"@scalar/oas-utils": "0.1.6",
1415
"classnames": "^2.5.1",
1516
"flatted": "^3.2.9",
1617
"openapi-types": "^12.1.3",

packages/react-openapi/src/OpenAPICodeSample.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22

33
import { CodeSampleInput, codeSampleGenerators } from './code-samples';
4-
import { OpenAPIOperationData } from './fetchOpenAPIOperation';
4+
import { OpenAPIOperationData, toJSON } from './fetchOpenAPIOperation';
55
import { generateMediaTypeExample } from './generateSchemaExample';
66
import { InteractiveSection } from './InteractiveSection';
77
import { getServersURL } from './OpenAPIServerURL';
@@ -70,14 +70,19 @@ export function OpenAPICodeSample(props: {
7070
return null;
7171
}
7272

73+
async function fetchOperationData() {
74+
'use server';
75+
return toJSON(data);
76+
}
77+
7378
return (
7479
<InteractiveSection
7580
header="Request"
7681
className="openapi-codesample"
7782
tabs={samples}
7883
overlay={
7984
data['x-hideTryItPanel'] || data.operation['x-hideTryItPanel'] ? null : (
80-
<ScalarApiButton />
85+
<ScalarApiButton fetchOperationData={fetchOperationData} />
8186
)
8287
}
8388
/>

packages/react-openapi/src/OpenAPIOperation.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { OpenAPIResponseExample } from './OpenAPIResponseExample';
88
import { OpenAPIServerURL } from './OpenAPIServerURL';
99
import { OpenAPISpec } from './OpenAPISpec';
1010
import { OpenAPIClientContext, OpenAPIContextProps } from './types';
11-
import { ApiClientModalProvider } from '@scalar/api-client-react';
11+
import { ScalarApiClient } from './ScalarApiButton';
1212

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

2424
const clientContext: OpenAPIClientContext = {
2525
defaultInteractiveOpened: context.defaultInteractiveOpened,
26-
specUrl: context.specUrl,
2726
icons: context.icons,
2827
};
2928

3029
return (
31-
<ApiClientModalProvider
32-
configuration={{ spec: { url: context.specUrl } }}
33-
initialRequest={{ path: data.path, method: data.method }}
34-
>
30+
<ScalarApiClient>
3531
<div className={classNames('openapi-operation', className)}>
3632
<div className="openapi-intro">
3733
<h2 className="openapi-summary" id={context.id}>
@@ -67,6 +63,6 @@ export function OpenAPIOperation(props: {
6763
</div>
6864
</div>
6965
</div>
70-
</ApiClientModalProvider>
66+
</ScalarApiClient>
7167
);
7268
}

0 commit comments

Comments
 (0)