Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Make Hugo's LiveReload work on RStudio Server#738

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
yihui wants to merge5 commits intomain
base:main
Choose a base branch
Loading
fromrstudio-server-livereload

Conversation

@yihui
Copy link
Contributor

@yihuiyihui commentedNov 4, 2022
edited
Loading

Unfortunately this doesn't work because I ran into an RStudio Server problem that I can't work around. The problem can be reproduced in the following steps. First create a new site and serve it:

install.packages('blogdown')blogdown::new_site('test-site',serve=TRUE)

The default port is 4321. We can fetchlivereload.js successfully from Hugo server via this port:

readLines('http://localhost:4321/livereload.js')# [1] "!function(){return function e(t,o,n){...# ...# [34] "};"# [35] ""# [36] "LiveReload.addPlugin(HugoReload)"

However, it can no longer be correctly loaded if we try to load it via the translated URL (I substituted random strings withxxxxxx):

u=rstudioapi::translateLocalUrl('http://localhost:4321/livereload.js',absolute=TRUE)u# [1] "https://xxxxxx.app.rstudio.cloud/p/xxxxxx/livereload.js"readLines(u)# [1] "<!DOCTYPE html>"# [2] "<html lang=\"en\">"# [3] "<head>"# [4] "<meta name=\"author\" content=\"RStudio, PBC\">"# [5] "<meta charset=\"utf-8\">"# [6] ""# [7] "<meta name=\"test:template\" content=\"login\">"# [8] "<meta name=\"description\" content=\"Log in to RStudio.\">"# [9] "<title>RStudio - Log In</title>"# ...

It doesn't work either if we paste the URL in the web browser's address bar. By comparison, all other assets work well, e.g.,https://xxxxxx.app.rstudio.cloud/p/xxxxxx/css/main.css. Also note that if we try to accesslivereload.js without the.js extension, we get a status code400 (bad request) instead of the usual404:https://xxxxxx.app.rstudio.cloud/p/xxxxxx/livereload

It seems that RStudio Server has a special routing mechanism for the filenamelivereload.js no matter if this file is served by which server (in this case, Hugo). This interference prevents Hugo's LiveReload from working.I wonder if this is a bug of RStudio Server.

…udio.cloud/p/hex, and use it as the baseURL, so that both livereload.js can be loaded (gohugoio/hugo#6698), and absolute URLs will work (this needes to be fixed because not all Hugo templates use the `relURL` function---some do generate absolute URLs, which will fail on RStudio server)
…RLs (ah, this is too complicated to explain...)
…t get around---RStudio Server seems to intefere with loading Hugo's livereload.js via the proxied port (the script can be read directly from the port, though)
@cderv
Copy link
Collaborator

@yihui I don't know fully the context here but just a reminder aboutrstudio/rstudio#8096 that we added in#496

Slightly related, but maybe another issue as the RStudio IDE could have been using specific treatment, probably meant for Quarto which uses livereload.js I think.

Anyway, you're onto it!

@yihui
Copy link
ContributorAuthor

Yes, I do rememberrstudio/rstudio#8096 well. That helped to some extent, and we have been "cheating" in the sense that we are refreshing the RStudio viewer by ourselves, instead of letting Hugo do it. This has a few limitations:

  1. It only works for R Markdown posts when users click the Knit button. It doesn't work with.md posts, and doesn't work when Rmd is automatically rendered to.md or.html on save. For this problem, I can provide an ugly workaround, though (watch for changes in.md/.html by myself and refresh viewer if necessary).
  2. Hugo's command-line option--navigateToChanged doesn't work. For this problem, I don't see any workaround on my side.

Originally Hugo had a bug (gohugoio/hugo#6698) so there was no hope that itslivereload.js could work on RStudio Server. It has been fixed later. Now I know how to make it work, but I ran into this RStudio Server bug and I don't see a possible workaround. Let's see if the Pro team could fix it:https://github.com/rstudio/rstudio-pro/issues/4012

cderv reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@yihui@cderv

[8]ページ先頭

©2009-2025 Movatter.jp