Skip to content
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

Disable menu/scroll tracking in ApiSchema #158

Merged
merged 2 commits into from
Mar 28, 2022
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
5 changes: 5 additions & 0 deletions .changeset/orange-peaches-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'docusaurus-theme-redoc': patch
---

Disable anchor tracking on scroll in ApiSchema component
12 changes: 10 additions & 2 deletions packages/docusaurus-theme-redoc/src/theme/ApiSchema/ApiSchema.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import clsx from 'clsx';
import { ThemeProvider } from 'styled-components';
import '../../global';
Expand All @@ -16,7 +16,15 @@ const ApiSchema: React.FC<Props> = ({
...rest
}: Props): JSX.Element => {
const specProps = useSpecData(id);
const { store } = useSpec(specProps);
const { store, darkStore, lightStore } = useSpec(specProps);

useEffect(() => {
/**
* @see https://github.com/Redocly/redoc/blob/823be24b313c3a2445df7e0801a0cc79c20bacd1/src/services/MenuStore.ts#L273-L276
*/
lightStore.menu.dispose();
darkStore.menu.dispose();
}, [lightStore, darkStore]);

return (
<ThemeProvider theme={store.options.theme}>
Expand Down
16 changes: 11 additions & 5 deletions packages/docusaurus-theme-redoc/src/utils/useSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function useSpec({ spec, url }: SpecProps) {
const { isDarkTheme } = useColorMode();
const themeOptions = usePluginData<GlobalData>('docusaurus-theme-redoc');

const result = useMemo(() => {
const stores = useMemo(() => {
const { lightTheme, darkTheme, options: redocOptions } = themeOptions;

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

return {
// @ts-expect-error extra prop
hasLogo: !!spec.info?.['x-logo'],
lightStore,
darkStore,
store: isBrowser && isDarkTheme ? darkStore : lightStore,
};
}, [isBrowser, spec, fullUrl, themeOptions, isDarkTheme]);
}, [isBrowser, spec, fullUrl, themeOptions]);

const result = useMemo(() => {
return {
...stores,
// @ts-expect-error extra prop
hasLogo: !!spec.info?.['x-logo'],
store: isBrowser && isDarkTheme ? stores.darkStore : stores.lightStore,
};
}, [isBrowser, isDarkTheme, spec, stores]);

return result;
}