Skip to content

Commit

Permalink
Disable menu/scroll tracking in ApiSchema (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit-gohri committed Mar 28, 2022
1 parent 7134ab9 commit 9d35116
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
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;
}

1 comment on commit 9d35116

@vercel
Copy link

@vercel vercel bot commented on 9d35116 Mar 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.