HubPress / hubpress.io

A web application to build your blog on GitHub
MIT License
2.81k stars 2.63k forks source link

Included source blocks are reloaded on each keystroke #474

Open gquintana opened 7 years ago

gquintana commented 7 years ago

The scenario:

  1. Open the browser debugger to watch the network traffic
  2. Edit an existing post like the one below
  3. Try to add some text in the post editor
  4. On each keystroke, the awesome.go file reloaded with an Ajax request and interrupts keyboard input
= Test

:source_dir: ../sources

Look how awesome is my code:

[source,go]
----
include::{source_dir}/awesome.go[tags=main]
----
jaredmorgs commented 7 years ago

Is this happening with Live Preview activated, or just with the raw AsciiDoc view @gquintana ?

I know that the Live Preview would trigger a view refresh as asciidoctor.js re-rendered the file. But I wouldn't expect it to re-trigger the render when the live preview was hidden.

gquintana commented 7 years ago

@jaredmorgs No includes are reloaded even if preview panel is hidden. Yet, I found a workaround setting config.meta.delay to 10s or more: it slows down to a refresh every 10s, this makes online post editor usable again. https://github.com/HubPress/hubpress.io/blob/development/src/hubpress/scripts/components/Post.react.js#L64

jaredmorgs commented 7 years ago

I'd say that @anthonny needs to disconnect the editor pane refresh from the live preview refresh.

Also, I'd recommend that you update to 0.7.0 and see if the problem persists. Could you confirm here once you've updated if the include macros still cause the editor pane lag.

Thanks for your help with testing this for us. 👍

anthonny commented 7 years ago

This a bit more complex that just a refresh.

I explain:

Each time you change the content of your post, a conversion in HTML is made by asciidoctor and the result is save in the pouchdb database. This content is use when you publish your post.

If you set the delay to 10 second, the editor will wait 10 second before generate the HTML content. If you close the editor at 9sec, the HTML will not be generated and not save so you will lose your content.

IMHO the best thing to do is to cache the ajax call for X second