Skip to content

Commit 9d35116

Browse files
authored
Disable menu/scroll tracking in ApiSchema (#158)
1 parent 7134ab9 commit 9d35116

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

.changeset/orange-peaches-applaud.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'docusaurus-theme-redoc': patch
3+
---
4+
5+
Disable anchor tracking on scroll in ApiSchema component

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import clsx from 'clsx';
33
import { ThemeProvider } from 'styled-components';
44
import '../../global';
@@ -16,7 +16,15 @@ const ApiSchema: React.FC<Props> = ({
1616
...rest
1717
}: Props): JSX.Element => {
1818
const specProps = useSpecData(id);
19-
const { store } = useSpec(specProps);
19+
const { store, darkStore, lightStore } = useSpec(specProps);
20+
21+
useEffect(() => {
22+
/**
23+
* @see https://github.com/Redocly/redoc/blob/823be24b313c3a2445df7e0801a0cc79c20bacd1/src/services/MenuStore.ts#L273-L276
24+
*/
25+
lightStore.menu.dispose();
26+
darkStore.menu.dispose();
27+
}, [lightStore, darkStore]);
2028

2129
return (
2230
<ThemeProvider theme={store.options.theme}>

packages/docusaurus-theme-redoc/src/utils/useSpec.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function useSpec({ spec, url }: SpecProps) {
2020
const { isDarkTheme } = useColorMode();
2121
const themeOptions = usePluginData<GlobalData>('docusaurus-theme-redoc');
2222

23-
const result = useMemo(() => {
23+
const stores = useMemo(() => {
2424
const { lightTheme, darkTheme, options: redocOptions } = themeOptions;
2525

2626
const commonOptions: Partial<RedocRawOptions> = {
@@ -42,13 +42,19 @@ export function useSpec({ spec, url }: SpecProps) {
4242
});
4343

4444
return {
45-
// @ts-expect-error extra prop
46-
hasLogo: !!spec.info?.['x-logo'],
4745
lightStore,
4846
darkStore,
49-
store: isBrowser && isDarkTheme ? darkStore : lightStore,
5047
};
51-
}, [isBrowser, spec, fullUrl, themeOptions, isDarkTheme]);
48+
}, [isBrowser, spec, fullUrl, themeOptions]);
49+
50+
const result = useMemo(() => {
51+
return {
52+
...stores,
53+
// @ts-expect-error extra prop
54+
hasLogo: !!spec.info?.['x-logo'],
55+
store: isBrowser && isDarkTheme ? stores.darkStore : stores.lightStore,
56+
};
57+
}, [isBrowser, isDarkTheme, spec, stores]);
5258

5359
return result;
5460
}

0 commit comments

Comments
 (0)