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

fix clicking on search result from same page doesn't scroll to the heading #4048

Merged
merged 19 commits into from
Jan 25, 2025
Prev Previous commit
Next Next commit
upd
  • Loading branch information
dimaMachina committed Jan 24, 2025
commit b17477ef458e3d3ca77f31e3682084cb7357e189
13 changes: 8 additions & 5 deletions packages/nextra/src/client/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ export const Search: FC<SearchProps> = ({
return
}
}
const { results } =
await window.pagefind!.debouncedSearch<PagefindResult>(
value,
searchOptions
)
const response = await window.pagefind!.debouncedSearch<PagefindResult>(
value,
searchOptions
)
if (!response) return

const { results } = response

const data = await Promise.all(results.map(o => o.data()))

setResults(
Expand Down
24 changes: 18 additions & 6 deletions packages/nextra/src/server/__tests__/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,9 @@ describe('Code block', () => {
<h3
id="pnpm"
style={{
display: 'none'
visibility: 'hidden',
height: 0,
width: 0
}}
>
{'pnpm'}
Expand All @@ -652,7 +654,9 @@ describe('Code block', () => {
<h3
id="npm"
style={{
display: 'none'
visibility: 'hidden',
height: 0,
width: 0
}}
>
{'npm'}
Expand All @@ -665,7 +669,9 @@ describe('Code block', () => {
<h3
id="yarn"
style={{
display: 'none'
visibility: 'hidden',
height: 0,
width: 0
}}
>
{'yarn'}
Expand All @@ -681,7 +687,9 @@ describe('Code block', () => {
<h3
id="pnpm-1"
style={{
display: 'none'
visibility: 'hidden',
height: 0,
width: 0
}}
>
{'pnpm'}
Expand All @@ -694,7 +702,9 @@ describe('Code block', () => {
<h3
id="npm-1"
style={{
display: 'none'
visibility: 'hidden',
height: 0,
width: 0
}}
>
{'npm'}
Expand All @@ -707,7 +717,9 @@ describe('Code block', () => {
<h3
id="yarn-1"
style={{
display: 'none'
visibility: 'hidden',
height: 0,
width: 0
}}
>
{'yarn'}
Expand Down