From ad0b4b1ed86b5da8bf2b6de48393ce95900be24e Mon Sep 17 00:00:00 2001 From: endiliey Date: Thu, 31 Oct 2019 23:24:48 +0700 Subject: [PATCH] fix(v2): @theme/heading should not create anchor if id is not defined --- CHANGELOG-2.x.md | 1 + .../src/theme/Heading/index.js | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG-2.x.md b/CHANGELOG-2.x.md index a874228a857a..fd154b2b5680 100644 --- a/CHANGELOG-2.x.md +++ b/CHANGELOG-2.x.md @@ -20,6 +20,7 @@ function Home() { ([#1860](https://github.com/facebook/Docusaurus/issues/1860)) ### Bug Fixes +- Fix MDX `@theme/Heading` component. If there is no id, it should not create anchor link. - Fixed a bug in which if `themeConfig.algolia` is not defined, the custom searchbar won't appear. If you've swizzled Algolia `SearchBar` component before, please update your source code otherwise CSS might break. See [#1909](https://github.com/facebook/docusaurus/pull/1909/files) for reference. ```js diff --git a/packages/docusaurus-theme-classic/src/theme/Heading/index.js b/packages/docusaurus-theme-classic/src/theme/Heading/index.js index 789e637a2790..eb596f8fd587 100644 --- a/packages/docusaurus-theme-classic/src/theme/Heading/index.js +++ b/packages/docusaurus-theme-classic/src/theme/Heading/index.js @@ -11,14 +11,19 @@ import React from 'react'; import './styles.css'; -const Heading = Tag => ({id, ...props}) => ( - - - {props.children} - -); +const Heading = Tag => ({id, ...props}) => { + if (!id) { + return ; + } + return ( + + + {props.children} + + ); +}; export default Heading;