Fix doubled request to the playpen on pages with an editor when accessed directly#340
Merged
Conversation
Contributor
|
@japaric Do you remember if there was an intentional reason for doing the initialization twice? |
|
@brson IIRC there was a bug (long time ago) where the editor didn't get initialized when the page was changed. For that reason I merged #84, which bind the editor initialization to the page.change event. I didn't realize that we may be initializing the editor twice. @dbbrian If you remove that call, does the editor still gets initialized when you first land at e.g. http://rustbyexample.com/hello.html I assume there is no page.change event in that scenario? |
Contributor
Author
|
@japaric It's weird naming, but yes, the |
japaric
pushed a commit
that referenced
this pull request
Dec 24, 2014
Fix doubled request to the playpen on pages with an editor when accessed directly
|
@dbbrian Thanks for investigating this! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

There is a global call to
initEditor()in node_modules/gitbook-plugin-rust-playpen/book/editor.js:115 that is triggered when a page is loaded. The problem is thatinitEditor()is also called by gitbook onpage.changeevents.As
initEditor()is responsible for binding the buttons with their handlers, those bindings are done twice when accessing a page directly: by the global call when the page is loaded, and by thepage.changeevent that is also fired on page load. So when clicking the “Run” button, its handler is called twice, causing two requests to be made to the playpen.I’ve put a
console.log()stuffed version ofeditor.jshere, so it will be easier for everyone to test.