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

[BLOCKING] Browser crash everytime when using the searchbar from an anchorlink #1670

Closed
etiennedesign opened this issue Jan 12, 2017 · 17 comments
Labels

Comments

@etiennedesign
Copy link

etiennedesign commented Jan 12, 2017

I met a critical issue.

Reproduction steps:

1 - Go to https://etiennedesign.gitbooks.io/test-gitbook-3/content/
2 - Click on a link on the sidebar
3 - Type in the searchbar
4 - The browser crash due to javascript error

Things i tried:

  • Use API theme
  • Use default theme
  • Remove custom css
  • Use html anchor links
  • Use Gitbook natural anchor links (# My Title --> #my-title)
  • Empty the book.json
  • Add "maxIndexSize": 2000000, to lunr configuration

Mozilla error message:

screen shot 2017-01-12 at 12 02 13 pm

@etiennedesign
Copy link
Author

The issue can be reproduce everytime on the Gitbook documentation as well, tested on different browser and computers

gitbook-crash-issue

@etiennedesign etiennedesign changed the title Browser crash when i click on anchor links and use the searchbar [BLOCKING] Browser crash everytime when using the searchbar from an anchorlink Jan 17, 2017
@jaredmorgs
Copy link

I tested on Chrome macOS latest release.

On your book the browser stops responding on the tab.

On https://toolchain.gitbook.com/setup.html I can select a topic, and then type solutio and the results are loaded directly.

Is your book public @etiennedesign ? My first guess is that it would be an incompatibility with lunr and one of the plug-ins. I did have issues with this when using the theme-faq plug-in in the earlier days of GitBook.

@nagim
Copy link

nagim commented Jan 19, 2017

@jaredmorgs The issue occurs when the summary entry points to an anchor inside the article (for example: https://toolchain.gitbook.com/syntax/markdown.html#emphasis).

@etiennedesign I tested a bit, and the behavior is really odd: if you click on the summary entry, it scrolls into the chapter, to the appropriate heading. That could be the problem. If you click on the summary entry and scroll up to the top, you can search then without freezing.

@SamyPesse @Soreine any ideas?

@etiennedesign
Copy link
Author

Thanks for your replies.

@jaredmorgs i made you collaborator so you can see, i don't think it is due to my configuration or plugins because i tested it on several books with default plugin and it freeze. A dev friend told me it seems to be a memory leak, like a process which multiply infinitely, a loop or something.. maybe the function which take each letter to refine the search..

@nagim exactly, if i look in the url browser bar, when i scroll to the top it works because i have https://toolchain.gitbook.com/syntax/markdown.html , as soon as i have #something anchor at the end it freeze when i type in the searchbar.
Maybe it has something to do with the scroll animation conflicting with the search plugin?

@jaredmorgs
Copy link

I've taken a closer look at your second comment when you are testing it on the Toolchain docs. And I can replicate the bug:

Test 1

Procedure

  1. Load https://toolchain.gitbook.com/syntax/markdown.html#emphasis
  2. Type te into the search field and notice lunr continues to return results.
  3. Complete the search string with d and notice the behaviour.

Actual Results

lunr search stops responding and the browser tab crashes.

Test 2

Procedure

  1. Load https://toolchain.gitbook.com/syntax/markdown.html
  2. Position cursor in search but don't type ted.
  3. In the browser awesome bar, the URL will be appended with https://toolchain.gitbook.com/syntax/markdown.html?q=
  4. type ted at the end.
  5. Press Enter.

Actual Results

You get a "No results matching ted" message but the browser still stops responding.

Other observations

Naked .md link in https://toolchain.gitbook.com/plugins/hooks.html on the text string "It is recommended using templating to extend page parsing."

@etiennedesign
Copy link
Author

@nagim

After testing with the plugin you sent me (search-plus), the same issue occur.

I also noticed that when you add internal links inside a page then click on it, the searchbar is working properly.
So the issue is not about anchorlinks, i think it may be caused by the animation which highlight the current link in the nav bar when you scroll the page.

Is there a way to remove this animation?

gitbook-searchbar-bug

@nagim
Copy link

nagim commented Feb 8, 2017

Yes, it must be the scrolling mechanism.

@SamyPesse this issue is quite serious, basically you cannot use search if you have scrolled down in a page, because it crashes instantly.

@harmvandendorpel
Copy link

+1

@etiennedesign
Copy link
Author

@nagim i am pretty sure this issue is due to the scroll-linked positionning effect. this is the message i get from the Mozilla console:

screen shot 2017-03-28 at 12 34 46 pm
https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Scroll-linked_effects

Do you know a way i could desactivate this function in the theme.js ? It would be a temporary solution.

@AaronO
Copy link

AaronO commented Aug 3, 2017

A quick update to this thread to let you know that I was debugging this issue this afternoon, in order to backport a fix and do a 3.2.3 release.

The issue seems to be an infinite loop (in some scenarios) in the event handler that scrolls to the appropriate part of the page when the URL changes.

Specifically the issue seems to be here:
https://github.com/GitbookIO/theme-default/blob/e0038f5c02ae666d16828661f5f6327ac3f67cc4/src/js/theme/navigation.js#L74-L78

The stop condition of that loop isn't very strict ...

@AaronO
Copy link

AaronO commented Aug 3, 2017

I have a local fix working, will try and get this out in a 3.2.3 release as soon as possible

@nagim
Copy link

nagim commented Aug 3, 2017

That's great news, @AaronO!

While you're at it, can you investigate this as well: if I open a link from outside the book (e.g.: from email) pointing to a section/anchor in a page, it doesn't jump to the right place.
To be more precise: the page loads, and it jumps to the anchor correctly. However, it seems that the sidebar is loaded after this event and this throws off the position to somewhere else.
Tried with almost all browsers (Firefox, Chrome, IE, etc.)

Thanks in advance!

@AaronO
Copy link

AaronO commented Aug 3, 2017

@nagim Can you report this another bug, because it seems to work on our official docs: https://toolchain.gitbook.com/syntax/markdown.html#emphasis (built with 3.2.2). What you're seeing is possibly a plugin issue.

I'm gonna keep this release focused on fixing the key issue here.

@nagim
Copy link

nagim commented Aug 3, 2017

Will do, thanks!

@AaronO
Copy link

AaronO commented Aug 3, 2017

Everyone, this is fixed the newly minted 3.2.3 release and will be deployed to gitbook.com shortly.

@AaronO
Copy link

AaronO commented Aug 3, 2017

This fix is live on gitbook.com and in the 3.2.3 release !

@cjdbarlow
Copy link

Thank you! This has been my no. 1 issue for ages. Love your work.

esproul pushed a commit to circonus/irondb-docs that referenced this issue Aug 25, 2017
If you search while viewing a page at an HTML anchor/fragment,
it causes a JS error that makes the tab/browser spin out of control.

GitbookIO/gitbook#1670
Kyddjam added a commit to Kyddjam/gitbook that referenced this issue Sep 13, 2017
cycomachead added a commit to cycomachead/gitbook that referenced this issue Jan 16, 2018
* master: (145 commits)
  Bump version to 3.2.3
  Update theme-default to 1.0.7 (fixes GitbookIO#1670)
  Bump version to 3.2.2
  Rollback to use [email protected]
  Correctly handle page parsing errors
  Add comment
  Add changes for 3.2.1
  Bump version to 3.2.1
  Update [email protected]
  Use [email protected]
  fixing a typo of the word "publishing" (GitbookIO#1536)
  Update examples.md (GitbookIO#1522)
  Fixed typo
  Fix command for getting gitbook version
  Create template for GitHub issues
  Add OSX testing on Travis
  Bump version to 3.2.0
  Update [email protected]
  Fix GitbookIO#1408: fix i18n in website generator and add tests for it
  editPlugin and getPluginConfig
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants