-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Add LiveReload #663
Add LiveReload #663
Conversation
Deploy preview for docusaurus-preview ready! Built with commit 5584173 |
😮 👍 ❤️ 🎉 I wake up to see this! This is so exciting! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excited about the PR! I'll let @JoelMarcey have a final look through before merging.
lib/core/Site.js
Outdated
@@ -159,6 +159,9 @@ class Site extends React.Component { | |||
}} | |||
/> | |||
))} | |||
{process.env.NODE_ENV !== 'production' && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of checking whether it's production
, check whether it's development
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok 👍. I went with it this way cause when debugging locally I did a console.log of process.env.NODE_ENV
and it was undefined. But could be development or !process.env.NODE_ENV
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's because it's not being set yet. I set it programmatically in server.js
so that the user does not have to do anything in addition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(To clarify, still confused why it was undefined locally...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh I see, thanks for the clarification 👍. Sorry typed my latest before refreshing the page to see your comment about it not being set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, process.env
looks at your process environmental variables. To set it outside of your code, you could do:
$ NODE_ENV=development npm run start
That would require users to have to change the way they start the server, which isn't ideal. I was thinking of passing in a prop developmentMode
to all the top-level components like Site
, BlogLayout
, and read from it when determining whether to inject LiveReload. But there are too many places to add so I don't think it's a good idea to do so. Hence we set the variable in server/server.js
.
lib/core/Site.js
Outdated
@@ -159,6 +159,9 @@ class Site extends React.Component { | |||
}} | |||
/> | |||
))} | |||
{process.env.NODE_ENV !== 'production' && ( | |||
<script src="http://localhost:35729/livereload.js" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This port number needs to be consistent with the server configuration. Hence extract the port out into a constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍thanks, this is a good improvement, makes sense
lib/server/server.js
Outdated
|
||
// Gaze watches some specified files and triggers a callback when they change. | ||
gaze( | ||
['../docs/**/*', 'blog/**/*', 'pages/**/*', 'static/**/*'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to listen on the entire website
dir.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
1d99b14
to
c44590e
Compare
Add to docs/, website/blog/, website/pages/, and website/static
c44590e
to
11bf350
Compare
lib/server/server.js
Outdated
gaze( | ||
[ | ||
'../docs/**/*', // docs | ||
'./**/*', // website |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't quite grok why the dot syntax doesn't work in https://github.com/shama/gaze and minimatch, especially isaacs/minimatch#30. (LiveReload doesn't "fire up" in the terminal like the gif with this syntax here.)
Switched it to just star syntax in the latest commit. Let me know what you think...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok let's switch it to **/*
lib/server/server.js
Outdated
@@ -559,7 +559,7 @@ function execute(port) { | |||
gaze( | |||
[ | |||
'../docs/**/*', // docs | |||
'./**/*', // website | |||
'*/*.*', // website |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, maybe this approach is flawed re: https://stackoverflow.com/a/21835063/2628398. If some file was in root of website it wouldn't be watched.
Off to sleep, will revisit this tomorrow...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last thing, it's confusing that **/*.*
doesn't work...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.*
specifies any extension and is redundant because *
would do the same (in most cases).
If some file was in root of website it wouldn't be watched.
Correct. */*.*
only looks at the files directly website/<dir>
, files which are deeper such as pages/en/index.js
would not be watched.
One last thing, it's confusing that **/. doesn't work...
**/*.*
works for me.
I think **/*
is the safest and is what we need. What's the rationale for changing to */*.*
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the confusion!
With the ./**/*
syntax there LiveReload doesn't start up. It seems to be because of the starting .
. It hangs like the gif at the end.
HEAD is now at 11bf350 Tweak code a little
alam@tesla website ((HEAD detached at 11bf350)) $ yarn start
yarn run v1.6.0
warning package.json: No license field
$ node ../lib/start-server.js
Delete the .*
syntax locally and everything is fine:
alam@tesla website (amy/add-livereload-final) $ git co 2c264e898efda48ccd6bca9ad7e5f8225fce1c82
Note: checking out '2c264e898efda48ccd6bca9ad7e5f8225fce1c82'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at 2c264e8 Simplify process.env call
alam@tesla website ((HEAD detached at 2c264e8)) $ yarn start
yarn run v1.6.0
warning package.json: No license field
$ node ../lib/start-server.js
Starting Docusaurus server on http://localhost:3000
Livereload listening on 35729...
So now how to fix watching all of website/
? Locally, change to **/*.*
. It also doesn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even delete docs (which is wrong) and just [ '**/*', // website ],
doesn't run, like the gif?
Something else I'm missing? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's super odd. Is working fine for me. Could you reinstall the dependencies or at worst, fetch a clean copy of the repository?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change it back to **/*
for now. I'm pretty confident that's the right path to specify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path for recursive files under website
is now incorrect IMO. @amyrlam could you verify?
I changed it to `**/*. But it still doesn't work for me, same behavior as the gif in the thread. I rm -rf'd the directory, re-cloned and did a Stumped rn re: what's wrong with my local setup |
@JoelMarcey could you help give it a go locally? |
Let me check this out - I wonder if the local |
I can push an update to |
@JoelMarcey sure, I can also debug my issue separately from this PR, whatever is easier... Hm I've been using |
We have had both. (whether we need both, that may be another question?). And you also changed My initial feeling here is that there is some conflict going on with you locally. But I am not 100% sure yet. |
I have it working again finally! 😅 I "nombom'd" and blew away node_modules in root and I'm not quite sure what happened, but I'm seeing reliable results with npm now. |
Tested on another MacBook of mine and it works. @JoelMarcey I think it's good to ship. Would be great if you got to try it out too! |
@amyrlam @yangshun I tested on my machine and it works! I tested changing some docs, some pages (e.g. This is great! The only things that didn't live reload were some changes to Not sure we can do much about that, but it could be something we try to update later. The colors would probably be most useful to live reload, I think. |
Hi, sorry if I interfered in this discussion. This is awesome. Waiting this to be shipped. I've tried it locally and it works Human are curious by nature, so I digged a little bit to see what's wrong. Modified amy's lib/server/server.js gaze part to debug
Then, I went to edit primaryColor in siteconfig.js LiveReload happens but the css is not changed. I had to Notice that main.css is not re-built on reload. It's only built once on Maybe we could trigger the css generation & sent it to user if Hopefully this help ! |
I'm aware of this limitation in this PR and I think it's fine to ship as-is. The part about supporting siteConfig can be found in this task #267 |
I 100% agree that we can ship this as-is. I will say one thing -- I changed the image path in |
@endiliey not interfering at all, appreciate you chiming in! 👍 Yes I'm seeing the same thing as @JoelMarcey re: colors. I'm not sure why this is happening yet, but probably that the colors are only loaded on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ 😍
Motivation
Resolves: #234
Have you read the Contributing Guidelines on pull requests?
yes!
Test Plan
LiveReload now works on save. LiveReload is watching
docs/
,blog/
,pages/
andstatic/
.I QA'd the
process.env.NODE_ENV === 'production'
case locally. Inwebsite/package.json
, I changedyarn start
to"start": "NODE_ENV=production node ../lib/start-server.js"
. I then confirmed with a freshyarn start
that LiveReload wasn't running in the terminal, or present in the browser.Related PRs
Updated the docs
admin/testing-changes-on-Docusaurus-itself.md
in this PR.cc @yangshun please let me know if any feedback, can make edits!