-
-
Notifications
You must be signed in to change notification settings - Fork 331
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
Website in Viewer is updated before Rmd rendering #486
Comments
Out of curiosity I tried on Ubuntu with Rstudio Server and the website does do not update... having the echo of stout hugo process helps see the website is correctly updated. Maybe an issue with newer version of hugo ? |
So live reload is working well with last hugo version when I test without R
That means LiveReload is working well and This is just not working correctly with Rmd post, and I believe it is because of the issue you mentioned : All the files are watched by the hugo server (including intermediates files) and this is surely causing issue to reload to the correct file. IMO this impact the experience while working in RStudio |
I think this is mostly because Using page bundles will make it much better. I was working on it yesterday, but didn't manage to finish it. Another thing is that we have to ignore The bug gohugoio/hugo#3811 that I mentioned may be irrelevant. It will be great if it could be fixed, but I don't think it's the culprit for the failure of |
This is indeed what I observe if I run the server hugo server in a Terminal and read what is printed as output when I modify the files. Lots of file watched and removes and written.
Those are intermediary files that are temporary during the Rmd building right ? Is it a bad idea to set
I was under the impression that, as all the files are watched included the ignored file, |
I'm not very comfortable with using
The challenge is that you can't easily move an Rmd file away and render it elsewhere when it references external files (e.g., As I said, with page bundles, this can be much easier. The Perhaps I should just provide an option and let users decide if they want to move HTML dependencies to I'll keep experimenting. I probably can't make the auto navigation work perfectly for the coming CRAN release. One thing is for sure: the experience of writing pure Markdown post will be much much better. Knitting individual posts used to be a totally wrong action for users to do, and now at least pressing the Knit button won't hurt any more. I guess that's already a huge step forward, despite the annoyance of excessive auto-refreshing and lack of support for auto-navigation. |
I ended up using a dirty trick 04ef6ee to let Hugo know for sure which page it should navigate to. The trick was to wait for 2 seconds after building the Rmd file, and rewrite it one more time. It seems to work for both page bundles and non-bundles. There is still unnecessary refreshing. I'll see if I can fix it tomorrow. |
Ok it is not working as I thought. I wonder if some parameters should pass to |
And I think this is because RStudio server act as a proxy. There is even a function in > rstudioapi::translateLocalUrl("https://localhost:6380/livereload.js")
[1] "p/56a946ed/livereload.js" Currently, as the error above it tries to load We may need to configure hugo server to know this ... 🤔 |
I have this trick for RStudio Server: Lines 656 to 663 in ba977a9
but it can't fix the problem of the path of livereload.js , because it's not controlled by the configuration relativeurls . I have also tried to use rstudioapi::translateLocalUrl() to change the baseURL temporarily before, but I don't remember why it didn't work now. I'll experiment one more time.
|
Yep I am trying that but with no sucess for now. |
This is probably one of the reasons why I didn't use |
Yes the live reloading would work ok in that case. Having RStudio using a It is too bad the relative url trick does not work for this js resource but does for other css and jss of the website. Because the preview is working well. I don't know if many people are using blogdown on rstudio server (or RStudio cloud) |
We could file a bug report to Hugo, but I don't feel hopeful that it could be fixed (especially if we don't actually submit a PR to fix it), because this is indeed a rare use case.
#124 has some examples. That was the motivation behind the trick of setting |
yes it is not really cool this does not work well on Rstudio server. But I guess hugo itself is not working well. BTW, changing the base url does not seems to affect where the livereload.js is fetched. The requested url in the Browser Network pane still show a request URL without any change to the base url. I think this is related to gohugoio/hugo#1187 |
Actually I've been thinking for long about the possibility of connecting to the websocket from R. If we have access to the data that Hugo and the web browser send to each other, we could probably do something (like refreshing a page or auto-navigation) on our end. But I guess in this case, the websocket is not even successfully established in the first place... Another crazy idea is that we could open a browser in a background thread in R to process the request |
I believe the issue may come from here |
The idea I want to experiment is to see if we don't serve the website from memory but we write to a folder, we would have access to the html file and we could change the script tag maybe to correctly load the js script. I am experimenting with this now. |
That's an absolute URL relative to the domain root. It's not a completely relative URL. See the second bullet in the last list: https://bookdown.org/yihui/blogdown/html.html This Yet another idea is to modify <script src="/livereload.js?port=4321&mindelay=10&v=2" data-no-instant defer></script> to <script src="/p/56a946ed/livereload.js?port=4321&mindelay=10&v=2" data-no-instant defer></script> on the page using JavaScript (
I guess this won't work, because Hugo dynamically injects the |
This is included in the html file written to disk by Hugo server if you set the option HUGO_RELATIVEURLS=true hugo server -w -d preview When you use this, hugo is no more serving from memory but from disk cderv@DESKTOP-D24Q6VQ:~/test-blogdown$ HUGO_RELATIVEURLS=true hugo server -w -d preview
Start building sites …
| EN
-------------------+-----
Pages | 20
Paginator pages | 0
Non-page files | 0
Static files | 15
Processed images | 0
Aliases | 0
Sitemaps | 1
Cleaned | 0
Built in 9 ms
Watching for changes in /home/cderv/test-blogdown/{content,static,themes}
Watching for config changes in /home/cderv/test-blogdown/config.toml
Environment: "development"
Serving pages from /home/cderv/test-blogdown/preview
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at //localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop this will create a preview directory (that I believe you could delete when killing the server as when served from memory it even does not exist) - It is just a temp dir on disk instead on cached memory. In all HTML files there is <script src="/livereload.js?port=1313&mindelay=10&v=2" data-no-instant defer></script> inserted in removing the leading / fix the error 404, the file is found (so 200) But i now get another error
|
Okay, great! Then there is still hope :)
Unfortunately I don't know this means... |
Seems related to proxy (again) : https://stackoverflow.com/a/49731895/3436535 |
And indeed RStudio server get the field in the response header
|
Too bad. Another hope is to see if the rstudioapi package could give us a method to refresh the viewer, e.g., Once we have that, we can refresh the viewer by ourselves after compiling the Rmd. Of course, we won't have the auto-navigation, but that shouldn't be too bad, because I think in most cases, users only work on one post, so refreshing the same page should be good enough. |
Yep - we could also see with product team if something can be done in RStudio Server to make hugo livereload worked...
Yes it seems a good path to follow - more probability of success I guess.
If we know the modified file (the one saved or knited), we could call Regarding the absolute path insertion, I wonder if livereload should inserted with a relative url to solve the issue linked above on Hugo repo. Seems odd that it is absolute but it seems to have always been that - it was using |
Regarding the API, there is already a bunch of command available using
Full list of commands https://docs.rstudio.com/ide/server-pro/rstudio-ide-commands.html |
Right. I need to refresh the currently opened page. Clicking the refresh button in the Viewer won't work. |
So I guess the conclusion of this investigation is that in order to have auto reload on rstudio server,
First option seems the one we could try. |
Yes Actually if Of course, if it's possible to do a real reload of the current URL in the Viewer, we won't need this |
If we can easily know the url of webpage for a post, we could also call
but |
I believe with
blogdown.knit.on_save
activated, the viewer is reloaded before the Rmd is rerendered with the change. At least, in most of the time and on Windows.This cause the viewer to not show the last change but the previous one.
Steps when this happens
See #481 for full workflow
Maybe related to --navigateToChanged not working ?
Let's note that it works ok if the post is opened in the browser
There is something not stable in this I believe. I'll look into it based on these notes.
The text was updated successfully, but these errors were encountered: