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

null link after clicking on search result that is the root page #39

Open
wojtek-jarosz opened this issue Mar 11, 2021 · 2 comments
Open

Comments

@wojtek-jarosz
Copy link

Site under test: https://optimistic-wilson-f4030f.netlify.app/

After typing in "Payload" and hitting enter, we're redirected to a "null" link :https://optimistic-wilson-f4030f.netlify.app/null

The slug of the page is set to "/" (it's a main page) so probably that's the issue here

Also the links displayed are "Payload#" instead of "Payload"

@neoakris
Copy link

I just encountered this bug today as well.

snippet of my docusaurus.config.js

  plugins: [  //adds search to the top right, using clientside javascript via lunr
      [require.resolve('docusaurus-lunr-search'),
          { //options for the plugin
            indexBaseUrl: true,
            languages: ['en']
          }
      ]
  ], //end plugins

It builds and indexes fine, but when I got to search for something that exists on the root of my site.
Clicking the search results, ends up redirecting me to /null instead of /

I suspect I might be able to work around the issue by leveraging client side redirect logic
https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-client-redirects
redirecting /null -> / might work as a hack fix

@neoakris
Copy link

Note in case someone else bumps into this, my idea didn't work, this would have to be solved at javascript code level.

  plugins: [  //adds search to the top right, using clientside javascript via lunr
      [require.resolve('docusaurus-lunr-search'),
          { //options for the plugin
            indexBaseUrl: true, //has a bug where search results on root direct to /null instead of /
            languages: ['en']
          }
      ], 
      ['@docusaurus/plugin-client-redirects', //attempt to fix bug on clientside search by introducing /null --> / redirect
          { //options for the plugin
            redirects: [
              {
                from: '/null',
                to: '/'
              }
            ]
          }
      ]
  ], //end plugins  

The following experimental config would often cause the local search to freeze with grey loading text in the search box / remain frozen and unclickable. Page refresh could sometimes fix it. The search results would still redirect to /null, even with this clientside redirect.

(And I was able to test that the clientside redirect was working because if I refreshed the /null page it would redirect to /, or if I typed it directly into the browser and pressed enter it'd redirect, just doesn't redirect through the search functionality.) I'm just going to set the indexBaseUrl: false to avoid the issue for now.

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

No branches or pull requests

2 participants