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

The search index is not available #1247

Closed
zhangporco opened this issue Mar 26, 2020 · 15 comments
Closed

The search index is not available #1247

zhangporco opened this issue Mar 26, 2020 · 15 comments

Comments

@zhangporco
Copy link

It's my typedoc.json file

{
  "inputFiles": ["./src"],
  "mode": "modules",
  "out": "docs",
  "ignoreCompilerErrors": true,
  "disableOutputCheck": true,
  "excludeExternals": true,
  "excludePrivate": true,
  "excludeNotExported": true
}

What can I do to use search

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Mar 30, 2020

Check your browser console when trying to load search - are some errors showing up? Search should be enabled by default.

@eidng8
Copy link

eidng8 commented Apr 20, 2020

It says search.js 404.

Here's my config:

  "typedocOptions": {
    "excludeExternals": true,
    "excludeNotExported": true,
    "excludePrivate": true,
    "excludeProtected": true,
    "inputFiles": "src",
    "out": "docs"
  },

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Apr 20, 2020

search.js isn't used anymore in 0.17.4, it should be looking for search.json. What version of typedoc-default-themes are you building with?

@eidng8
Copy link

eidng8 commented Apr 20, 2020

I have installed typedoc-default-themes specifically. I'm using "typedoc": "^0.17.4". And I've checked that it indeed has installed 0.17.4.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Apr 20, 2020

If you run npm ls typedoc-default-themes, is the version 0.10.1?

@eidng8
Copy link

eidng8 commented Apr 21, 2020

npm ls --depth=1
...
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected] deduped
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected] deduped
│ ├── [email protected] deduped
│ ├── [email protected]
│ └── [email protected]
├── [email protected]
...

@ferhtgoldaraz
Copy link

ferhtgoldaraz commented Apr 21, 2020

Try serving de docs with something like https://www.npmjs.com/package/serve

npx serve docs

The search component is doing a fetch, and on the other hand the search.js file is being injected with document.write (even in 0.10.1). This is only done for file:// protocol, which suggests you might just be opening the html without a server, but then fetch may not work (chrome only allows it in http or https).

@eidng8
Copy link

eidng8 commented Apr 21, 2020

It's a theme problem. I swap it out and if works fine. Sorry for the mess.

@Fleker
Copy link
Contributor

Fleker commented Jul 23, 2020

Is there a strong reason for the removal of this search.js? Being able to open the files directly in my browser is a quick way to make sure the pages load as expected. I don't know how much work it is to maintain it, but it seems like it introduces friction to have to spin up a server just to load what would otherwise be static HTML files.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jul 26, 2020

Good question, I believe @sgrishchenko's original motivation was to reduce the possibility for code injection. As a part of the transition to JSON, it also improved the page load speed by doing indexing when building the docs rather than whenever anyone loaded the page. The latter is more important to me than storing it in a JSON file, and I agree that it would be nice to be able to use the docs without starting a server... I'd be open to reverting to a JS file.

@sgrishchenko
Copy link
Contributor

@Fleker Sorry, but I don't understand why we should use JavaScript to transfer static data? If you want use brouser preview, you can use json file the same way, here the screen of json from my documentation site (https://sgrishchenko.github.io/reselect-utils/typedoc/light/assets/js/search.json). It works fine for me.
image

@Fleker
Copy link
Contributor

Fleker commented Jul 27, 2020

@sgrishchenko that approach works fine when you are hosting the files on GitHub or some other server, but it does not work if you try to open the files locally file:///usr/.../docs/index.html, where I get the error:

main.js:6 Fetch API cannot load file:///usr/.../docs/assets/js/search.json. URL scheme must be "http" or "https" for CORS request.

Unless I take the advice above and have to spin up a local server using npx serve docs.

Having an improvement in speed is definitely beneficial, but being able to run locally through some fallback behavior would still be useful.

The theme default.hbs previously had the line:

<script>if (location.protocol == 'file:') document.write('<script src="{{relativeURL "assets/js/search.js"}}"><' + '/script>');</script>

which could return to provide some sort of substitute implementation when the script is activated.

@sgrishchenko
Copy link
Contributor

@Fleker Oh, now I see, thank you, but it looks like a hack for me. What if tomorrow Google Chrome or Firefox says that JS files should be loaded via "http" or "https" too? Shall we explore another hack to make workaround for this case?

@sgrishchenko
Copy link
Contributor

sgrishchenko commented Jul 28, 2020

@Fleker But may be it is not bad to make some hacks to improve DX, maybe it will be better to have two modes: development and production. JS will be used in development mode and JSON - in production. Or maybe typedoc should start up some development server (e.g. webpack-dev-server) like CRA or Storybook does.

@Fleker
Copy link
Contributor

Fleker commented Jul 28, 2020

If Chrome or Firefox implemented a particular limitation, then it'd probably make sense for Typedoc to make another workaround as Typedoc is built for web browsers and are tied to platform requirements.

Having a development mode, which would be functionally the same as production, would be beneficial in trying out the doc rendering quickly.

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

6 participants