Skip to content

Commit ae43b81

Browse files
authored
Render in browser in dev mode if url (#207)
1 parent f172bb3 commit ae43b81

File tree

7 files changed

+1582
-1553
lines changed

7 files changed

+1582
-1553
lines changed

.changeset/big-mice-move.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'docusaurus-plugin-redoc': patch
3+
'docusaurus-theme-redoc': patch
4+
---
5+
6+
Fix reloads in dev mode

packages/docusaurus-plugin-redoc/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export default function redocPlugin(
122122
const data: SpecProps = {
123123
url,
124124
themeId,
125+
isSpecFile,
125126
// eslint-disable-next-line @typescript-eslint/no-explicit-any
126127
spec: content.converted as any,
127128
};
@@ -133,7 +134,7 @@ export default function redocPlugin(
133134
: options.route;
134135

135136
const specProps = await createData(
136-
`redocApiSpecV1.1-${options.id || '1'}.json`,
137+
`redocApiSpecV1.2-${options.id || '1'}.json`,
137138
JSON.stringify(data),
138139
);
139140
const layoutProps = await createData(

packages/docusaurus-theme-redoc/src/theme/Redoc/Redoc.tsx

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import React from 'react';
22
import clsx from 'clsx';
33
import '../../global';
4-
import { Redoc as RedocComponent, RedocRawOptions } from 'redoc';
4+
import {
5+
Redoc as RedocComponent,
6+
RedocStandalone,
7+
RedocRawOptions,
8+
} from 'redoc';
59
import { SpecProps } from '../../types/common';
610
import { useSpec } from '../../utils/useSpec';
711
import { ServerStyles } from './Styles';
@@ -25,6 +29,22 @@ function Redoc(
2529
optionsOverrides,
2630
);
2731

32+
const isDevMode = process.env.NODE_ENV === 'development';
33+
34+
if (isDevMode && specProps.isSpecFile === false) {
35+
return (
36+
<div
37+
className={clsx([
38+
'redocusaurus',
39+
hasLogo && 'redocusaurus-has-logo',
40+
className,
41+
])}
42+
>
43+
<RedocStandalone specUrl={specProps.url} options={store.rawOptions} />
44+
</div>
45+
);
46+
}
47+
2848
return (
2949
<>
3050
<ServerStyles

packages/docusaurus-theme-redoc/src/theme/Redoc/ServerStyles.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ export function ServerStyles({
5858
lightThemeOptions,
5959
darkThemeOptions,
6060
}: {
61-
specProps: SpecProps,
62-
lightThemeOptions: RedocRawOptions,
63-
darkThemeOptions: RedocRawOptions,
61+
specProps: SpecProps;
62+
lightThemeOptions: RedocRawOptions;
63+
darkThemeOptions: RedocRawOptions;
6464
}) {
6565
const fullUrl = useBaseUrl(specProps.url, { absolute: true });
6666
const css = {

packages/docusaurus-theme-redoc/src/types/common.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type ParsedSpec = OpenAPISpec;
77
export interface SpecProps {
88
spec: ParsedSpec;
99
url?: string;
10+
isSpecFile?: boolean;
1011
themeId?: string;
1112
}
1213

packages/docusaurus-theme-redoc/src/types/modules.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ interface SpecProps {
22
// eslint-disable-next-line @typescript-eslint/no-explicit-any
33
spec: import('redoc/typings/types').OpenAPISpec;
44
url?: string;
5+
isSpecFile?: boolean;
56
themeId?: string;
67
}
78

0 commit comments

Comments
 (0)