Skip to content

Fix doubled request to the playpen on pages with an editor when accessed directly#340

Merged
japaric merged 1 commit into
rust-lang:masterfrom
dbbrian:double_request_to_playpen
Dec 24, 2014
Merged

Fix doubled request to the playpen on pages with an editor when accessed directly#340
japaric merged 1 commit into
rust-lang:masterfrom
dbbrian:double_request_to_playpen

Conversation

@dbbrian

@dbbrian dbbrian commented Dec 19, 2014

Copy link
Copy Markdown
Contributor

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 that initEditor() is also called by gitbook on page.change events.

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 the page.change event 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 of editor.js here, so it will be easier for everyone to test.

@brson

brson commented Dec 22, 2014

Copy link
Copy Markdown
Contributor

@japaric Do you remember if there was an intentional reason for doing the initialization twice?

@japaric

japaric commented Dec 24, 2014

Copy link
Copy Markdown

@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?

@dbbrian

dbbrian commented Dec 24, 2014

Copy link
Copy Markdown
Contributor Author

@japaric It's weird naming, but yes, the page.change event is also fired on page load.
screen shot 2014-12-24 at 17 12 59

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
@japaric japaric merged commit e677758 into rust-lang:master Dec 24, 2014
@japaric

japaric commented Dec 24, 2014

Copy link
Copy Markdown

@dbbrian Thanks for investigating this!

@dbbrian dbbrian deleted the double_request_to_playpen branch February 15, 2015 15:10
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

Successfully merging this pull request may close these issues.

3 participants