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

feat(search): implements Orama searchbox #6908

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

micheleriva
Copy link
Contributor

Description

As discussed with @ovflowd, this PR implements the official Orama Searchbox.

Validation

Related Issues

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run npm run format to ensure the code follows the style guide.
  • I have run npm run test to check if all tests are passing.
  • I have run npx turbo build to check if the website builds without errors.
  • I've covered new added functionality with unit tests if necessary.

Copy link

vercel bot commented Jul 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nodejs-org ✅ Ready (Inspect) Visit Preview Nov 29, 2024 4:38pm

@bmuenzenmeyer
Copy link
Collaborator

Sorry @micheleriva this has been idle for too long - it's been a messy few weeks. Are you looking for any particular feedback on the approach?

@ovflowd
Copy link
Member

ovflowd commented Jul 31, 2024

Looks like this is a draft yet, and most of the styles feel broken 🤔

Copy link

github-actions bot commented Jul 31, 2024

Unit Test Coverage Report

Lines Statements Branches Functions
Coverage: 91%
90.2% (580/643) 72.08% (173/240) 93.96% (109/116)

Unit Test Report

Tests Skipped Failures Errors Time
137 0 💤 0 ❌ 0 🔥 4.9s ⏱️

@micheleriva
Copy link
Contributor Author

Hey @bmuenzenmeyer, @ovflowd I'm sorry, I completely missed your comments. We found some bugs in the searchbox and dedicated more time to stabilize it.

We've been testing it for weeks on other websites so we believe it is finally ready. I still have to fix a small couple of things, then I'll open it for review 🙏

@micheleriva micheleriva marked this pull request as ready for review August 21, 2024 18:33
@micheleriva micheleriva requested a review from a team as a code owner August 21, 2024 18:33
@ovflowd ovflowd added the github_actions:pull-request Trigger Pull Request Checks label Aug 21, 2024
@github-actions github-actions bot removed the github_actions:pull-request Trigger Pull Request Checks label Aug 21, 2024
@ovflowd
Copy link
Member

ovflowd commented Aug 21, 2024

FYI @micheleriva build is failing:

@nodejs/website:build: Error: 
@nodejs/website:build:   x Expression expected
@nodejs/website:build:      ,-[128:1]

Did you try a prod build locally?

@ovflowd
Copy link
Member

ovflowd commented Aug 29, 2024

image

It feels like the results are less obvious.

@ovflowd
Copy link
Member

ovflowd commented Aug 29, 2024

Also it'd be great if there was some margin between the results

@ovflowd

This comment was marked as resolved.

@rjborba
Copy link

rjborba commented Nov 27, 2024

@ovflowd FYI we also started using next router to navigate. Experience should be smoother now. ✅

@ovflowd
Copy link
Member

ovflowd commented Nov 27, 2024

@rjborba, this is just an FYI: the AI-generated Markdown links are still broken. This can be done in a follow-up PR, but just a FYI, They don't have the language prefixes.

@ovflowd
Copy link
Member

ovflowd commented Nov 27, 2024

Also, I wonder how much extra bundle is added just for the search box. Can you give us some insights? We want to ensure that the users' experience is smooth.

@rjborba
Copy link

rjborba commented Nov 28, 2024

@rjborba, this is just an FYI: the AI-generated Markdown links are still broken. This can be done in a follow-up PR, but just a FYI, They don't have the language prefixes.

Hi @ovflowd it is actually fixed. But it takes in consideration the BASE_URL constant, which is resolving for something different than the ones on the Markdown answer on Next Preview.

We've added a callback to the Markdown URL so we have a opportunity to modify the HREF in runtime, after the LLM generates it. We want to add the locale when URL starts with the base URL (https://nodejs.org) and does not have /docs as initial path.

We could enhance it by using something like window.location.host instead, but current implementations works just fine when the host URL matches the one generated by the chat.

onSearchResultClick={event => {
event.preventDefault();

const currentPageHost = `${window.location.protocol}//${window.location.host}`;
Copy link
Member

Choose a reason for hiding this comment

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

Can we not use window. APIs here at all, I'm pretty sure @/navigation's useRouter and usePathname have everything you need. Using global environment-based APIs hinders the ability of us to optimise this in the future.

Copy link

Choose a reason for hiding this comment

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

Hi!
I'm sorry, but I could not find a proper way to get current host through neither usePathname nor useRouter.
Also checked the other methods from createNavigation. Would you mind to let me know what API should I use?

Another solution would be go back to use "BASE_URL" from constants.

Please let me know

Copy link
Member

Choose a reason for hiding this comment

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

As mentioned before, you don't need to retrieve the host.

const currentPageHost = `${window.location.protocol}//${window.location.host}`;

router.push(`${currentPageHost}/${event.detail.result.path}`, {
locale: undefined,
Copy link
Member

Choose a reason for hiding this comment

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

Explain why this is set to undefined within inline docs

Copy link

Choose a reason for hiding this comment

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

The URL provided on the callback event (event.details.result.path) always contains the locale because of the resultMap property. URLs are already good to be clicked on searchbox, with the locale being dynamically appended.

In summary, router.push from @navigator always append the locale for not undefined locale. It is bad because:
A) For /docs paths, we can not have the locale
B) We already add the locale on resultMap

Copy link
Member

@ovflowd ovflowd Nov 29, 2024

Choose a reason for hiding this comment

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

I think you misunderstood me. I am asking you to add inline commentary on the code of why you passed this undefined; other people might not understand the why. (You don't need to explain the code; I 100% get how it works)

searchParams={DEFAULT_ORAMA_QUERY_PARAMS}
suggestions={DEFAULT_ORAMA_SUGGESTIONS}
chatMarkdownLinkHref={({ href }) => {
if (!href) return href;
Copy link
Member

Choose a reason for hiding this comment

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

Let's ensure we always use brackets on if statements.

Copy link

Choose a reason for hiding this comment

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

Thanks! Should we add it to lint rules?

Copy link
Member

Choose a reason for hiding this comment

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

Feel free to do so 💯

const docsBaseUrl = `${currentPageHost}/docs`;
const lowerCaseHref = href.toLowerCase();

// Keep original link if URl should not have locale
Copy link
Member

@ovflowd ovflowd Nov 28, 2024

Choose a reason for hiding this comment

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

Can you add the reasoning? This whole URL logic seems unnecessary, you can simply check if the href's pathname startsWith docs. You can accomplish that by

const { pathname } = new URL(href);

Copy link

Choose a reason for hiding this comment

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

Hi! The problem with your approach is that you are assuming that LLM will always reply with URLs related under nodes domain. What if one asks: can you give me the documentation URL from some companies that uses NodeJs?

Does it make sense to you?

Copy link
Member

Choose a reason for hiding this comment

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

Why do we care about comparing content from other domains? That's a pretty easy, if the URL does not start with https://nodejs.org then simply return href

That can be 100% hardcoded there and it is the simplest yet best approach here; You can add inline documentary explaining why and that the href can be other domains but we only care about nodejs.org domain

Copy link
Member

Choose a reason for hiding this comment

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

(Alternatively you can check against BASE_URL), the point is, these checks need to be deterministic. Using window.* is not deterministic and environment-specific.

@ovflowd
Copy link
Member

ovflowd commented Nov 28, 2024

OOC - Is there any way we can style the search button on the Navigation bar? It feels a bit fatty and different from the OG design 👀

@rjborba
Copy link

rjborba commented Nov 29, 2024

OOC - Is there any way we can style the search button on the Navigation bar? It feels a bit fatty and different from the OG design 👀

Currently we do not provide all possible customizations. We are going to work on it soon.
But if you want to costumize the roundness of the button you can define --radius-m variable.

@rjborba
Copy link

rjborba commented Nov 29, 2024

@ovflowd I've addressed you new comments, but dropped a reply on one of them. Would you mind to check? Thank you!

@ovflowd
Copy link
Member

ovflowd commented Nov 29, 2024

OOC - Is there any way we can style the search button on the Navigation bar? It feels a bit fatty and different from the OG design 👀

Currently we do not provide all possible customizations. We are going to work on it soon. But if you want to costumize the roundness of the button you can define --radius-m variable.

I see, it would be cool to allow we defining CSS variables; Like a templating system --ormama-button-something-something

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.

Accessibility Issues with Scrolling and Focus in WithSearchBox Modal
9 participants