Skip to content

[BUG] hooks run twice unexpectedly #1732

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

Closed
1 task
trusktr opened this issue Jan 23, 2022 · 3 comments · Fixed by #1736
Closed
1 task

[BUG] hooks run twice unexpectedly #1732

trusktr opened this issue Jan 23, 2022 · 3 comments · Fixed by #1736
Assignees
Labels
bug confirmed as a bug

Comments

@trusktr
Copy link
Member

trusktr commented Jan 23, 2022

Bug Report

Steps to reproduce

Not sure what the cause is yet, but I've written local playwright tests that verify that doneEach runs twice on initial page load for a particular test (so the case is isolated).

This is unexpected. For most sites/tests, doneEach runs once, but in some rare case it runs twice. I have experienced this before in practice too.

This might possibly explain what I was seeing in #906 with scripts running twice

What is current behaviour

doneEach runs twice on initial render sometimes.

What is the expected behaviour

It should run one time all the time, or twice all the time. Or something similar, but right now there is something that seems inconsistent.

Other relevant information

  • Bug does still occur when all/other plugins are disabled?

  • Your OS: Linux

  • Node.js version: 17

  • npm/yarn version: 8

  • Browser version: Chrome

  • Docsify version: 4.12.2

  • Docsify plugins: Added a plugin in docs/index.html to log, and log happens twice.

Please create a reproducible sandbox

Not sure how yet.

Mention the docsify version in which this bug was not present (if any)

@trusktr trusktr self-assigned this Jan 23, 2022
@trusktr trusktr added the bug confirmed as a bug label Jan 23, 2022
@trusktr trusktr changed the title hook.doneEach runs twice on initial page load sometimes. [BUG] hook.doneEach runs twice on initial page load sometimes. Jan 23, 2022
@trusktr
Copy link
Member Author

trusktr commented Jan 23, 2022

Here are two stack traces, one from each doneEach call, based on commit 9658ed4 with minification disabled, in lib/docsify.min.js:

      LOG FROM INSIDE PAGE, TEST 1:  RenderCountPlugin/<@http://127.0.0.1:3001/docs/index.html#/:238:27
      step@http://127.0.0.1:3001/lib/docsify.min.js:9908:36
      step@http://127.0.0.1:3001/lib/docsify.min.js:9910:19
      step@http://127.0.0.1:3001/lib/docsify.min.js:9910:19
      callHook@http://127.0.0.1:3001/lib/docsify.min.js:9917:13
      done@http://127.0.0.1:3001/lib/docsify.min.js:9687:16
      $fetch/<@http://127.0.0.1:3001/lib/docsify.min.js:9698:13
      fn@http://127.0.0.1:3001/lib/docsify.min.js:9606:13
      then/<@http://127.0.0.1:3001/lib/docsify.min.js:2919:20
      EventListener.handleEvent*on@http://127.0.0.1:3001/lib/docsify.min.js:2872:28
      then@http://127.0.0.1:3001/lib/docsify.min.js:2907:11
      loadNested@http://127.0.0.1:3001/lib/docsify.min.js:9548:79
      _loadSideAndNav/<@http://127.0.0.1:3001/lib/docsify.min.js:9610:21
      _renderMain/</<@http://127.0.0.1:3001/lib/docsify.min.js:9401:15
      prerenderEmbed/<@http://127.0.0.1:3001/lib/docsify.min.js:9103:13
      walkFetchEmbed@http://127.0.0.1:3001/lib/docsify.min.js:8963:14
      prerenderEmbed@http://127.0.0.1:3001/lib/docsify.min.js:9077:19
      _renderMain/<@http://127.0.0.1:3001/lib/docsify.min.js:9392:27
      step@http://127.0.0.1:3001/lib/docsify.min.js:9900:17
      step@http://127.0.0.1:3001/lib/docsify.min.js:9910:19
      callHook@http://127.0.0.1:3001/lib/docsify.min.js:9917:13
      _renderMain@http://127.0.0.1:3001/lib/docsify.min.js:9376:14
      _fetch/<@http://127.0.0.1:3001/lib/docsify.min.js:9640:40
      then/<@http://127.0.0.1:3001/lib/docsify.min.js:2919:20
      EventListener.handleEvent*on@http://127.0.0.1:3001/lib/docsify.min.js:2872:28
      then@http://127.0.0.1:3001/lib/docsify.min.js:2907:11
      _fetch@http://127.0.0.1:3001/lib/docsify.min.js:9640:15
      $fetch@http://127.0.0.1:3001/lib/docsify.min.js:9696:16
      initFetch@http://127.0.0.1:3001/lib/docsify.min.js:9773:16
      Docsify@http://127.0.0.1:3001/lib/docsify.min.js:9941:12
      @http://127.0.0.1:3001/lib/docsify.min.js:9962:22
      EventListener.handleEvent*documentReady@http://127.0.0.1:3001/lib/docsify.min.js:796:9
      @http://127.0.0.1:3001/lib/docsify.min.js:9962:16
      @http://127.0.0.1:3001/lib/docsify.min.js:9964:3
      LOG FROM INSIDE PAGE, TEST 1:  RenderCountPlugin/<@http://127.0.0.1:3001/docs/index.html#/:238:27
      step@http://127.0.0.1:3001/lib/docsify.min.js:9908:36
      step@http://127.0.0.1:3001/lib/docsify.min.js:9910:19
      step@http://127.0.0.1:3001/lib/docsify.min.js:9910:19
      callHook@http://127.0.0.1:3001/lib/docsify.min.js:9917:13
      done@http://127.0.0.1:3001/lib/docsify.min.js:9687:16
      $fetch/<@http://127.0.0.1:3001/lib/docsify.min.js:9698:13
      fn@http://127.0.0.1:3001/lib/docsify.min.js:9606:13
      then@http://127.0.0.1:3001/lib/docsify.min.js:2879:23
      loadNested@http://127.0.0.1:3001/lib/docsify.min.js:9548:79
      _loadSideAndNav/<@http://127.0.0.1:3001/lib/docsify.min.js:9610:21
      _renderMain/</<@http://127.0.0.1:3001/lib/docsify.min.js:9401:15
      prerenderEmbed/<@http://127.0.0.1:3001/lib/docsify.min.js:9103:13
      walkFetchEmbed@http://127.0.0.1:3001/lib/docsify.min.js:8963:14
      prerenderEmbed@http://127.0.0.1:3001/lib/docsify.min.js:9077:19
      _renderMain/<@http://127.0.0.1:3001/lib/docsify.min.js:9392:27
      step@http://127.0.0.1:3001/lib/docsify.min.js:9900:17
      step@http://127.0.0.1:3001/lib/docsify.min.js:9910:19
      callHook@http://127.0.0.1:3001/lib/docsify.min.js:9917:13
      _renderMain@http://127.0.0.1:3001/lib/docsify.min.js:9376:14
      _fetch/<@http://127.0.0.1:3001/lib/docsify.min.js:9640:40
      then@http://127.0.0.1:3001/lib/docsify.min.js:2879:23
      _fetch@http://127.0.0.1:3001/lib/docsify.min.js:9640:15
      $fetch@http://127.0.0.1:3001/lib/docsify.min.js:9696:16
      initRouter/<@http://127.0.0.1:3001/lib/docsify.min.js:1225:16
      onchange/<@http://127.0.0.1:3001/lib/docsify.min.js:1039:11
      EventListener.handleEvent*on@http://127.0.0.1:3001/lib/docsify.min.js:754:25
      onchange@http://127.0.0.1:3001/lib/docsify.min.js:1036:9
      initRouter@http://127.0.0.1:3001/lib/docsify.min.js:1215:16
      Docsify@http://127.0.0.1:3001/lib/docsify.min.js:9935:12
      @http://127.0.0.1:3001/lib/docsify.min.js:9962:22
      EventListener.handleEvent*documentReady@http://127.0.0.1:3001/lib/docsify.min.js:796:9
      @http://127.0.0.1:3001/lib/docsify.min.js:9962:16
      @http://127.0.0.1:3001/lib/docsify.min.js:9964:3

In this example, one doneEach happens due to the initFetch process, and the other happens due to the initRouter process.

@trusktr trusktr changed the title [BUG] hook.doneEach runs twice on initial page load sometimes. [BUG] hooks run twice unexpectedly Jan 24, 2022
@trusktr
Copy link
Member Author

trusktr commented Jan 26, 2022

This may be an issue that only happens in an e2e test (as I just discovered), although I thought I experienced this before elsewhere.

@jhildenbiddle
Copy link
Member

Addressed by #1736.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug confirmed as a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants