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

Works not with language parameters #6

Closed
tanrak opened this issue Apr 28, 2020 · 13 comments
Closed

Works not with language parameters #6

tanrak opened this issue Apr 28, 2020 · 13 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@tanrak
Copy link

tanrak commented Apr 28, 2020

I have tested the plugin and found that it does not work with other languages.
For example an excerpt from my mkdocs.yml:

theme:
    name: material
    custom_dir: theme
#    language: de

plugins:
    - search:
        lang:
#            - de
            - en
    - localsearch

Commented (with hash) it works, but commented out (without hash) it does not work.

Edit: Browser is Firefox

@wilhelmer
Copy link
Owner

This seems to be an issue with MkDocs Material.

With the configuration above, I get the following console output (FF, file:// protocol):

TypeError: lunr.multiLanguage is undefined index.ts:148:15
Loading failed for the <script> with source “file:///C:/Temp/mkdocs-test/test/lunr/min/lunr.de.min.js”. index.html:1:1
Loading failed for the <script> with source “file:///C:/Temp/mkdocs-test/test/lunr/min/lunr.multi.min.js”. index.html:1:1
Loading failed for the <script> with source “file:///C:/Temp/mkdocs-test/test/lunr/min/lunr.stemmer.support.min.js”. index.html:1:1

With search.lang set to de only, I get:

TypeError: e is undefined lunr.js:2678:2
Loading failed for the <script> with source “file:///C:/Temp/mkdocs-test/test/lunr/min/lunr.de.min.js”. index.html:1:1
Loading failed for the <script> with source “file:///C:/Temp/mkdocs-test/test/lunr/min/lunr.stemmer.support.min.js”. index.html:1:1

The issue seems to be related to both the theme.language and the search.lang settings.

If I use a web server, everything works as expected.

@squidfunk Could you please look into this? I have attached a sample project: localsearch-issue-6.zip

@wilhelmer wilhelmer added bug Something isn't working help wanted Extra attention is needed labels Apr 29, 2020
@squidfunk
Copy link

Might be related to iframe-worker and importScripts, but needs further investigation. Currently, tight on time. Help appreciated.

@squidfunk
Copy link

squidfunk commented Apr 29, 2020

So, I took some minutes to investigate. It's indeed related to importScripts, as they're loaded directly before setting up the index, which means that the stemmers haven't loaded yet. This is a limitation of the polyfill which is stated in the caveats section.

What I just tested is whether we can return a Promise from importScripts, and it seems to work. The latest master of iframe-worker contains the fix. The cool thing is that we could now use async/await in Material for MkDocs to await on importScripts, as awaiting a function that does not return a Promise is a no-op. However, I don't have the time to make the necessary adjustments in the worker code and test whether the non-local (i.e. default) case still works. If somebody could pick up from here, I'd be grateful. The code in question is here.

I attached the patched iframe-worker runtime which passes all tests: polyfill.zip

@wilhelmer
Copy link
Owner

Not sure if that's what you wanted me to do, but I downloaded your ZIP file, added index.js to extra_javascript in the sample project, built the project and tested using Material 5.1.4:

  • FF & local: works ✔️
  • FF & non-local: works ✔️
  • Chrome & local: Search bar is gracefully hidden 🔴
  • Chrome & non-local: works ✔️

@squidfunk
Copy link

No, the search worker code needs to be adjusted to await on importScripts

@wilhelmer
Copy link
Owner

I tried, but couldn't get it to work. Sorry 😞 I have no experience with Typescript or async/await. I'm not a programmer, just a poor script kiddie.

@squidfunk
Copy link

squidfunk commented Aug 2, 2020

Support for awaitable importScripts was just added to Material for MkDocs Insiders ☺️ This should resolve the problems described in this issue, as the search index will now wait until the scripts have been loaded.

@wilhelmer
Copy link
Owner

wilhelmer commented Aug 3, 2020

Great, thanks. I'll check it out as soon as I have access to Insiders via my corporate account.

@squidfunk
Copy link

Great! We can work on this together from then on, so search works for your product after all. The funding goal for general availability is also not that far away.

@squidfunk
Copy link

The funding goal was hit, so let's revisit this issue when Material 6 is released, which should fix this problem. I'm pretty sure it's going to arrive this weekend. If the issue persists, we can work on it.

@wilhelmer
Copy link
Owner

Uuuh v6, it's gonna be a major release. Yes, let's do that.

@squidfunk
Copy link

squidfunk commented Sep 27, 2020

squidfunk/mkdocs-material@9fe00ec fixes this issue, by detecting iframe-worker inside the search worker, fixing up the base URL and loading the stemmers via awaited importScripts. Note that two bugfix releases of iframe-worker followed, i.e. 0.1.8 and 0.1.9, so make sure to use the latest version, which is 0.1.9. My testing shows that this issue is now resolved. I tested with the following configuration.

theme:
  name: material
  language: de

plugins:
  - search
  - localsearch

The fixes are not yet released, so for now you'll have to check master. A release should follow this week with some more post v6 bugfixes 😊

Just released it as 6.0.1.

@wilhelmer
Copy link
Owner

Also tested this, works like a charm. Thanks for your support 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants