Skip to content

Commit 9dac7d1

Browse files
authored
Merge ddc0a7c into df43d74
2 parents df43d74 + ddc0a7c commit 9dac7d1

File tree

10 files changed

+1625
-1555
lines changed

10 files changed

+1625
-1555
lines changed

.changeset/quiet-phones-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'docusaurus-theme-redoc': patch
3+
---
4+
5+
Fix flash of unstyled content

packages/docusaurus-theme-redoc/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"copyfiles": "^2.4.1",
3737
"lodash": "^4.17.21",
3838
"mobx": "^6.5.0",
39+
"react-hydration-on-demand": "^2.1.0",
3940
"redoc": "2.0.0-rc.72",
4041
"styled-components": "^5.3.5"
4142
},

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import '../../global';
33
import useBaseUrl from '@docusaurus/useBaseUrl';
4+
import withHydrationOnDemand from 'react-hydration-on-demand';
45
import { AppStore, Redoc, RedocRawOptions } from 'redoc';
56
// eslint-disable-next-line import/no-extraneous-dependencies
67
import { renderToString } from 'react-dom/server';
@@ -53,7 +54,7 @@ const prefixCssSelectors = function (rules: string, className: string) {
5354
const LIGHT_MODE_PREFIX = "html:not([data-theme='dark'])";
5455
const DARK_MODE_PREFIX = "html([data-theme='dark'])";
5556

56-
export function ServerStyles({
57+
function ServerStylesComponent({
5758
specProps,
5859
lightThemeOptions,
5960
darkThemeOptions,
@@ -102,3 +103,5 @@ export function ServerStyles({
102103
</div>
103104
);
104105
}
106+
107+
export const ServerStyles = withHydrationOnDemand()(ServerStylesComponent);
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import React from 'react';
2+
import withHydrationOnDemand from 'react-hydration-on-demand';
23
import '../../global';
34
import type { RedocRawOptions } from 'redoc';
45

56
/**
67
* Don't hydrate/replace server styles
78
* @see https://github.com/facebook/react/issues/10923#issuecomment-338715787
89
*/
9-
export function ServerStyles(_props: {
10+
function ServerStylesComponent(_props: {
1011
specProps: SpecProps;
1112
lightThemeOptions: RedocRawOptions;
1213
darkThemeOptions: RedocRawOptions;
1314
}) {
1415
return <div className="redocusaurus-styles"></div>;
1516
}
17+
18+
export const ServerStyles = withHydrationOnDemand()(ServerStylesComponent);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'react-hydration-on-demand';

packages/redocusaurus/Readme.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
1. Install redocusaurus:
1010

1111
```sh
12-
npm i --save redocusaurus
12+
npm i --save redocusaurus babel-plugin-styled-components@^2
1313
# OR
14-
yarn add redocusaurus
14+
yarn add redocusaurus babel-plugin-styled-components@^2
1515
```
1616

1717
1. Add it as a preset to your docusaurus config along with [@docusaurus/preset-classic](https://docusaurus.io/docs/using-plugins#docusauruspreset-classic) and pass options:
@@ -82,6 +82,15 @@
8282
};
8383
```
8484

85+
2. Add `babel-plugin-styled-components` to the plugins array of your `babel.config.js`:
86+
87+
```babel.config.js
88+
module.exports = {
89+
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
90+
plugins: ['babel-plugin-styled-components']
91+
};
92+
```
93+
8594
The API Doc will be available at the route specified (`/api/` in the example above). To customize it see [full plugin options](https://redocusaurus.vercel.app/docs/getting-started/plugin-options).
8695

8796
### Options

website/babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module.exports = {
22
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3+
plugins: ['babel-plugin-styled-components']
34
};

website/docs/getting-started/Installation.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ author_url: https://rohit.page
1212
```sh
1313
npm i --save redocusaurus
1414
# OR
15-
yarn add redocusaurus
15+
yarn add redocusaurus babel-plugin-styled-components@^2
1616
```
1717

1818
1. Add it as a preset to your docusaurus config along with [@docusaurus/preset-classic](https://docusaurus.io/docs/using-plugins#docusauruspreset-classic) and pass options:
@@ -83,6 +83,15 @@ yarn add redocusaurus
8383
};
8484
```
8585

86+
2. Add `babel-plugin-styled-components` to the plugins array of your `babel.config.js`:
87+
88+
```babel.config.js
89+
module.exports = {
90+
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
91+
plugins: ['babel-plugin-styled-components']
92+
};
93+
```
94+
8695
The API Doc will be available at the path specific by `route`. To skip adding a
8796
route altogether just don't set the `route` property. You will still be
8897
able to reference schema elements manually using [Schema Imports](/docs/guides/schema-imports) or create Custom React Pages using the data and theme components.

website/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
},
3232
"devDependencies": {
3333
"@percy/cli": "^1.3.0",
34-
"@types/react": "^17.0.45"
34+
"@types/react": "^17.0.45",
35+
"babel-plugin-styled-components": "^2.0.7"
3536
},
3637
"browserslist": {
3738
"production": [

0 commit comments

Comments
 (0)