Skip to content

Commit 8c1b9d5

Browse files
author
Dimitri POSTOLOV
authoredSep 4, 2023
remove <MatchSorterSearch /> (#2246)

17 files changed

+133
-214
lines changed
 

‎.changeset/wild-waves-invite.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'nextra-theme-docs': major
3+
---
4+
5+
remove `<MatchSorterSearch />`

‎.eslintrc.cjs

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module.exports = {
4747
'unicorn/no-array-for-each': 'error',
4848
'unicorn/prefer-string-replace-all': 'error',
4949
'@typescript-eslint/prefer-for-of': 'error',
50+
quotes: ['error', 'single', { avoidEscape: true }], // Matches Prettier, but also replaces backticks
5051
// todo: enable
5152
'@typescript-eslint/no-explicit-any': 'off',
5253
'@typescript-eslint/no-non-null-assertion': 'off',
@@ -104,6 +105,7 @@ module.exports = {
104105
],
105106
parserOptions: {
106107
project: [
108+
'examples/*/tsconfig.json',
107109
'packages/*/tsconfig.json',
108110
'docs/tsconfig.json',
109111
'tsconfig.eslint.json'

‎examples/swr-site/vercel.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"public": true
3+
}

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"react-dom": "^18.2.0",
5151
"@mdx-js/react": "^2.3.0",
5252
"next-themes": "^0.2.1",
53-
"next": "^13.4.8"
53+
"next": "^13.4.19"
5454
},
5555
"patchedDependencies": {
5656
"@changesets/assemble-release-plan@5.2.4": "patches/@changesets__assemble-release-plan@5.2.4.patch"

‎packages/nextra-theme-docs/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"focus-visible": "^5.2.0",
4646
"git-url-parse": "^13.1.0",
4747
"intersection-observer": "^0.12.2",
48-
"match-sorter": "^6.3.1",
4948
"next-seo": "^6.0.0",
5049
"next-themes": "^0.2.1",
5150
"scroll-into-view-if-needed": "^3.0.0",

‎packages/nextra-theme-docs/src/components/match-sorter-search.tsx

-43
This file was deleted.

‎packages/nextra-theme-docs/src/components/navbar.tsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import { Menu, Transition } from '@headlessui/react'
22
import cn from 'clsx'
33
import { useFSRoute } from 'nextra/hooks'
44
import { ArrowRightIcon, MenuIcon } from 'nextra/icons'
5-
import type { Item, MenuItem, PageItem } from 'nextra/normalize-pages'
5+
import type { MenuItem, PageItem } from 'nextra/normalize-pages'
66
import type { ReactElement, ReactNode } from 'react'
77
import { useConfig, useMenu } from '../contexts'
88
import { renderComponent } from '../utils'
99
import { Anchor } from './anchor'
1010

1111
export type NavBarProps = {
12-
flatDirectories: Item[]
1312
items: (PageItem | MenuItem)[]
1413
}
1514

@@ -81,7 +80,7 @@ function NavbarMenu({
8180
)
8281
}
8382

84-
export function Navbar({ flatDirectories, items }: NavBarProps): ReactElement {
83+
export function Navbar({ items }: NavBarProps): ReactElement {
8584
const config = useConfig()
8685
const activeRoute = useFSRoute()
8786
const { menu, setMenu } = useMenu()
@@ -165,10 +164,10 @@ export function Navbar({ flatDirectories, items }: NavBarProps): ReactElement {
165164
)
166165
})}
167166

168-
{renderComponent(config.search.component, {
169-
directories: flatDirectories,
170-
className: 'nx-hidden md:nx-inline-block mx-min-w-[200px]'
171-
})}
167+
{config.flexsearch &&
168+
renderComponent(config.search.component, {
169+
className: 'nx-hidden md:nx-inline-block mx-min-w-[200px]'
170+
})}
172171

173172
{config.project.link ? (
174173
<Anchor

‎packages/nextra-theme-docs/src/components/sidebar.tsx

+5-7
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ function Menu({
323323

324324
interface SideBarProps {
325325
docsDirectories: PageItem[]
326-
flatDirectories: Item[]
327326
fullDirectories: Item[]
328327
asPopover?: boolean
329328
headings: Heading[]
@@ -332,7 +331,6 @@ interface SideBarProps {
332331

333332
export function Sidebar({
334333
docsDirectories,
335-
flatDirectories,
336334
fullDirectories,
337335
asPopover = false,
338336
headings,
@@ -417,11 +415,11 @@ export function Sidebar({
417415
)}
418416
ref={containerRef}
419417
>
420-
<div className="nx-px-4 nx-pt-4 md:nx-hidden">
421-
{renderComponent(config.search.component, {
422-
directories: flatDirectories
423-
})}
424-
</div>
418+
{config.flexsearch && (
419+
<div className="nx-px-4 nx-pt-4 md:nx-hidden">
420+
{renderComponent(config.search.component)}
421+
</div>
422+
)}
425423
<FocusedItemContext.Provider value={focused}>
426424
<OnFocusItemContext.Provider
427425
value={item => {

‎packages/nextra-theme-docs/src/constants.tsx

+2-13
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
import type { NextSeoProps } from 'next-seo'
33
import { useRouter } from 'next/router'
44
import { DiscordIcon, GitHubIcon } from 'nextra/icons'
5-
import type { Item } from 'nextra/normalize-pages'
65
import type { FC, ReactNode } from 'react'
76
import { isValidElement } from 'react'
87
import { z } from 'zod'
98
import { Anchor, Flexsearch, Footer, Navbar, TOC } from './components'
10-
import { MatchSorterSearch } from './components/match-sorter-search'
119
import type { NavBarProps } from './components/navbar'
1210
import { themeOptionsSchema, ThemeSwitch } from './components/theme-switch'
1311
import type { TOCProps } from './components/toc'
@@ -115,9 +113,7 @@ export const themeSchema = z.strictObject({
115113
link: z.string().startsWith('https://').optional()
116114
}),
117115
search: z.strictObject({
118-
component: z.custom<
119-
ReactNode | FC<{ className?: string; directories: Item[] }>
120-
>(...reactNode),
116+
component: z.custom<ReactNode | FC<{ className?: string }>>(...reactNode),
121117
emptyResult: z.custom<ReactNode | FC>(...reactNode),
122118
error: z.string().or(z.function().returns(z.string())),
123119
loading: z.custom<ReactNode | FC>(...reactNode),
@@ -285,14 +281,7 @@ export const DEFAULT_THEME: DocsThemeConfig = {
285281
)
286282
},
287283
search: {
288-
component: function Search({ className, directories }) {
289-
const config = useConfig()
290-
return config.flexsearch ? (
291-
<Flexsearch className={className} />
292-
) : (
293-
<MatchSorterSearch className={className} directories={directories} />
294-
)
295-
},
284+
component: Flexsearch,
296285
emptyResult: (
297286
<span className="nx-block nx-select-none nx-p-8 nx-text-center nx-text-sm nx-text-gray-400">
298287
No results found.

‎packages/nextra-theme-docs/src/index.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ const InnerLayout = ({
125125
activePath,
126126
topLevelNavbarItems,
127127
docsDirectories,
128-
flatDirectories,
129128
flatDocsDirectories,
130129
directories
131130
} = useMemo(
@@ -186,7 +185,6 @@ const InnerLayout = ({
186185
<Banner />
187186
{themeContext.navbar &&
188187
renderComponent(config.navbar.component, {
189-
flatDirectories,
190188
items: topLevelNavbarItems
191189
})}
192190
<div
@@ -198,7 +196,6 @@ const InnerLayout = ({
198196
<ActiveAnchorProvider>
199197
<Sidebar
200198
docsDirectories={docsDirectories}
201-
flatDirectories={flatDirectories}
202199
fullDirectories={directories}
203200
headings={headings}
204201
asPopover={hideSidebar}

‎packages/nextra/__test__/compile.test.ts

+26-26
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,23 @@ export const TagName = () => {
5050
###### bar Qux [#]`,
5151
{ mdxOptions }
5252
)
53-
expect(result).toMatch(`<_components.h1 id="test-id">{"My Header"}`)
53+
expect(result).toMatch('<_components.h1 id="test-id">{"My Header"}')
5454
expect(result).toMatch(
55-
`<_components.h2 id="extra-space">{"Some extra space"}</_components.h2>`
55+
'<_components.h2 id="extra-space">{"Some extra space"}</_components.h2>'
5656
)
5757
expect(result).toMatch(
58-
`<_components.h3 id="extra-space-in-heading">{"Some extra space in heading"}`
58+
'<_components.h3 id="extra-space-in-heading">{"Some extra space in heading"}'
5959
)
6060
expect(result).toMatch(
61-
`<_components.h3 id="without-space">{"nospace"}</_components.h3>`
61+
'<_components.h3 id="without-space">{"nospace"}</_components.h3>'
6262
)
63-
expect(result).toMatch(`<_components.h4 id="другой-язык">{"foo"}`)
64-
expect(result).toMatch(`<_components.h5 id="bar-baz-">{"bar Baz []"}`)
65-
expect(result).toMatch(`<_components.h6 id="bar-qux-">{"bar Qux [#]"}`)
63+
expect(result).toMatch('<_components.h4 id="другой-язык">{"foo"}')
64+
expect(result).toMatch('<_components.h5 id="bar-baz-">{"bar Baz []"}')
65+
expect(result).toMatch('<_components.h6 id="bar-qux-">{"bar Qux [#]"}')
6666
})
6767
it('use github-slugger', async () => {
68-
const { result } = await compileMdx(`### My Header`, { mdxOptions })
69-
expect(result).toMatch(`<_components.h3 id="my-header">{"My Header"}`)
68+
const { result } = await compileMdx('### My Header', { mdxOptions })
69+
expect(result).toMatch('<_components.h3 id="my-header">{"My Header"}')
7070
})
7171

7272
it('should merge headings from partial components', async () => {
@@ -148,50 +148,50 @@ import Last from './three.mdx'
148148

149149
describe('Link', () => {
150150
it('supports .md links', async () => {
151-
const { result } = await compileMdx(`[link](../file.md)`, { mdxOptions })
152-
expect(result).toMatch(`<_components.a href="../file">`)
151+
const { result } = await compileMdx('[link](../file.md)', { mdxOptions })
152+
expect(result).toMatch('<_components.a href="../file">')
153153
})
154154

155155
it('supports .mdx links', async () => {
156-
const { result } = await compileMdx(`[link](../file.mdx)`, { mdxOptions })
157-
expect(result).toMatch(`<_components.a href="../file">`)
156+
const { result } = await compileMdx('[link](../file.mdx)', { mdxOptions })
157+
expect(result).toMatch('<_components.a href="../file">')
158158
})
159159

160160
it('supports URL links', async () => {
161-
const { result } = await compileMdx(`[link](../file)`, { mdxOptions })
162-
expect(result).toMatch(`<_components.a href="../file">`)
161+
const { result } = await compileMdx('[link](../file)', { mdxOptions })
162+
expect(result).toMatch('<_components.a href="../file">')
163163
})
164164

165165
it('supports query', async () => {
166-
const { result } = await compileMdx(`[link](../file.md?query=a)`, {
166+
const { result } = await compileMdx('[link](../file.md?query=a)', {
167167
mdxOptions
168168
})
169-
expect(result).toMatch(`<_components.a href="../file?query=a">`)
169+
expect(result).toMatch('<_components.a href="../file?query=a">')
170170
})
171171

172172
it('supports anchor', async () => {
173-
const { result } = await compileMdx(`[link](../file.md#anchor)`, {
173+
const { result } = await compileMdx('[link](../file.md#anchor)', {
174174
mdxOptions
175175
})
176-
expect(result).toMatch(`<_components.a href="../file#anchor">`)
176+
expect(result).toMatch('<_components.a href="../file#anchor">')
177177
})
178178

179179
it('supports external .md links', async () => {
180-
const { result } = await compileMdx(`[link](https://example.com/file.md)`, {
180+
const { result } = await compileMdx('[link](https://example.com/file.md)', {
181181
mdxOptions
182182
})
183-
expect(result).toMatch(`<_components.a href="https://example.com/file.md">`)
183+
expect(result).toMatch('<_components.a href="https://example.com/file.md">')
184184
})
185185

186186
it('supports external .mdx links', async () => {
187187
const { result } = await compileMdx(
188-
`[link](https://example.com/file.mdx)`,
188+
'[link](https://example.com/file.mdx)',
189189
{
190190
mdxOptions
191191
}
192192
)
193193
expect(result).toMatch(
194-
`<_components.a href="https://example.com/file.mdx">`
194+
'<_components.a href="https://example.com/file.mdx">'
195195
)
196196
})
197197
})
@@ -242,15 +242,15 @@ describe('Code block', () => {
242242
describe('Copy code button', () => {
243243
for (const codeHighlight of [true, false]) {
244244
describe(`codeHighlight: ${codeHighlight}`, () => {
245-
it(`attach with "copy"`, async () => {
245+
it('attach with "copy"', async () => {
246246
const { result } = await compileMdx('```js copy\n```', {
247247
mdxOptions,
248248
codeHighlight
249249
})
250250
expect(result).toMatch('hasCopyCode>')
251251
})
252252

253-
it(`attach with "defaultShowCopyCode: true"`, async () => {
253+
it('attach with "defaultShowCopyCode: true"', async () => {
254254
const { result } = await compileMdx('```js\n```', {
255255
mdxOptions,
256256
defaultShowCopyCode: true,
@@ -259,7 +259,7 @@ describe('Code block', () => {
259259
expect(result).toMatch('hasCopyCode>')
260260
})
261261

262-
it(`not attach with "defaultShowCopyCode: true" and "copy=false"`, async () => {
262+
it('not attach with "defaultShowCopyCode: true" and "copy=false"', async () => {
263263
const { result } = await compileMdx('```js copy=false\n```', {
264264
mdxOptions,
265265
defaultShowCopyCode: true,

‎packages/nextra/loader.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
*
77
* @todo once webpack supports ESM loaders, remove this wrapper.
88
*
9+
* @this {LoaderContext}
910
* @param {string} code
1011
*/
1112
module.exports = function (code) {
1213
const callback = this.async()
14+
1315
// Note that `import()` caches, so this should be fast enough.
1416
import('./dist/loader.mjs').then(mod =>
1517
mod.default.call(this, code, callback)

‎packages/nextra/src/loader.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ ${
289289
}
290290

291291
const stringifiedPageOpts =
292-
JSON.stringify(pageOpts).slice(0, -1) + `,headings:__toc}`
292+
JSON.stringify(pageOpts).slice(0, -1) + ',headings:__toc}'
293293
const stringifiedChecksum = IS_PRODUCTION
294294
? "''"
295295
: JSON.stringify(hashFnv32a(stringifiedPageOpts))

‎packages/nextra/src/locales.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function locales(request: NextRequest) {
3232

3333
if (/\/_meta(\.[a-z]{2}-[A-Z]{2})?$/.test(nextUrl.pathname)) {
3434
const url = nextUrl.clone()
35-
url.pathname = `/404`
35+
url.pathname = '/404'
3636
return NextResponse.rewrite(url)
3737
}
3838

‎packages/nextra/src/use-internals.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function useInternals() {
3737

3838
if (!context) {
3939
throw new Error(
40-
`No content found for the current route. This is a Nextra bug.`
40+
'No content found for the current route. This is a Nextra bug.'
4141
)
4242
}
4343

‎pnpm-lock.yaml

+77-109
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tsconfig.eslint.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
// ensure that nobody can accidentally use this config for a build
66
"noEmit": true
77
},
8-
"include": ["examples/swr-site/theme.config.tsx"],
8+
"include": [],
99
"exclude": []
1010
}

0 commit comments

Comments
 (0)
Please sign in to comment.