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(flexsearch): separate chain of calls into statements #739

Merged
merged 1 commit into from
May 18, 2022

Conversation

steven-mathew
Copy link
Contributor

@steven-mathew steven-mathew commented Apr 30, 2022

This makes the search bar continue to work when many (2000+) pages are added.

Summary

This adjusts the way in which the search index is built so that the call stack is not exceeded on some browsers (see #738 for browser compatibility). I'm not familiar with Hugo templating so if there's a preferred way, we can go that route!

Basic example

Previously, the compiled template would add to the array index by chaining .add() calls.

index.add(
{
  id: 3,
  href: "/docs/prologue/doc1/",
  title: "doc1",
  description: "Doks comes with commands for common tasks.",
  content: ""
})
.add(
{
  id: 4,
  href: "/docs/prologue/doc10/",
  title: "doc10",
  description: "Doks comes with commands for common tasks.",
  content: ""
})
.add(
{
  id: 5,
  href: "/docs/prologue/doc100/",
  title: "doc100",
  description: "Doks comes with commands for common tasks.",
  content: ""
})
...

Now, this PR would make the resulting template add to index without chaining, something like:

index.add(
  {
    id: 3,
    href: "/docs/prologue/doc1/",
    title: "doc1",
    description: "Doks comes with commands for common tasks.",
    content: ""
  }
);
index.add(
  {
    id: 4,
    href: "/docs/prologue/doc10/",
    title: "doc10",
    description: "Doks comes with commands for common tasks.",
    content: ""
  }
);
index.add(
  {
    id: 5,
    href: "/docs/prologue/doc100/",
    title: "doc100",
    description: "Doks comes with commands for common tasks.",
    content: ""
  }
);
...

Motivation

Closes #738

Checks

  • Read Create a Pull Request
  • Supports all screen sizes (if relevant)
  • Supports both light and dark mode (if relevant)
  • Passes npm run test

@h-enk
Copy link
Member

h-enk commented May 7, 2022

Thanks for this! Will take a closer look and do some testing later.

Copy link
Member

@h-enk h-enk left a comment

Choose a reason for hiding this comment

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

Tested + verified. Your solution is totally fine with me. Thanks for this!

@h-enk h-enk merged commit a8bf2bc into gethyas:master May 18, 2022
adhadse pushed a commit to adhadse/doks that referenced this pull request Sep 17, 2022
fix(flexsearch): separate chain of calls into statements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding many pages results in "RangeError: Maximum call stack size exceeded"
2 participants