-
Notifications
You must be signed in to change notification settings - Fork 337
feat: Implement livereloading for wrangler preview #252
Conversation
8207886
to
0ac995e
Compare
bb9d992
to
68972cb
Compare
4b9b39a
to
0e0034d
Compare
This is feature complete! Tagging @ejcx for security review on the wrangler side of this, specifically directed towards the websocket portion of this PR. |
f63473e
to
ed860ed
Compare
use std::thread; | ||
use std::time::Duration; | ||
|
||
pub const COOLDOWN_PERIOD: Duration = Duration::from_millis(2000); |
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.
Considering making this a config option, it refers to the amount of time wrangler will ignore new fs events when it detects the first one. Any new events during the cooldown period restart the timer.
just going to revert, os should clean the temp file in the temp dir on reboot anyways so we shouldn't need an explicit ctrlc handler |
7bb07f6
to
4b586ef
Compare
I'm mildly concerned about the stability of this feature, and I think maybe we should include it in a RC release first or gate it under an experimental flag. The worst thing that can happen however is a poor user experience -- the watcher not seeing an update or wrangler Especially with the |
this 502s for me locally :( unclear if it's related to #429, what would be useful for debugging here?
update: talked to @ashleygwilliams about this, the project is 502ing because it has KV bindings in |
this worked really well for me with a new application, nice work @xortive! one piece of feedback: as i watched the live reloading happen in the terminal, i found that it was unclear when the browser should be up-to-date. here's the terminal output i saw a few times as i made changes:
it seems like the "Updating preview with changes" step is always the last thing that happens before the preview actually, well, updates. would it make sense to change that text output to "Updated preview with changes", or have another line of output that indicates when the preview window is done updating? not a blocker, just stood out to me as i was trying this out |
&session.to_string(), ws_port, script_id, https_str, preview_host, | ||
))?; | ||
|
||
//don't do initial GET + POST with livereload as the expected behavior is unclear. |
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.
what do you mean here?
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.
we ignore the wrangler preview get --watch
and wrangler preview post --watch
commands as it is unclear what they should do. They will be addressed once we have a command for browserless preview
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 is looking really good with the new changes to authenticated preview! Want to wait for @ashleymichal and @signalnerve to review w/their KV projects before merging.
I think Kristian is going to take on writing up a section in the README.
One more todo for @xortive - please hide the sidebar for just merge this PR xortive#1wrangler preview
, this is looking awesome awesome!!
my previous issue w/ |
Co-Authored-By: Sven Sauleau <github@sauleau.com>
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.
lgtm!
own logic for picking a port
50d585e
to
b15fd59
Compare
b15fd59
to
6e19a8e
Compare
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.
<3
src/commands/build/watch/watcher.rs
Outdated
Ok(Some(path)) => { | ||
message::working("Detected changes..."); | ||
//wait for cooldown | ||
while let Ok(_e) = rx.recv_timeout(cooldown) { |
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.
convention here would be to just write Ok(_)
project: &Project, | ||
tx: Option<Sender<()>>, | ||
) -> Result<(), failure::Error> { | ||
let (mut command, temp_file, bundle) = setup_build(project)?; |
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.
long term we probably want a better solution here ;)
src/commands/build/wranglerjs/mod.rs
Outdated
let _command_guard = util::GuardedCommand::spawn(command); | ||
|
||
let (watcher_tx, watcher_rx) = channel(); | ||
let mut watcher = watcher(watcher_tx, Duration::from_secs(1)).unwrap(); |
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 am worried about these unwraps!
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.
if we can: let's get rid of unwraps- make them errors if at all possible. if not possible: info debugging lines would be very useful. ask yourself- when this panics.. what am i gonna want to know
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 is basically creating an expect
)
@@ -188,10 +200,18 @@ fn run() -> Result<(), failure::Error> { | |||
None => None, | |||
}; | |||
commands::init(name, project_type)?; | |||
} else if matches.subcommand_matches("build").is_some() { | |||
} else if let Some(matches) = matches.subcommand_matches("build") { |
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.
do we need build --watch?
src/main.rs
Outdated
@@ -207,7 +227,12 @@ fn run() -> Result<(), failure::Error> { | |||
None => None, | |||
}; | |||
|
|||
commands::preview(project, user, method, body)?; | |||
let watch = match matches.occurrences_of("watch") { |
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.
match presence of not occurences .. because what if someone types wrangler preview --watch --watch
closing in favor of #451 |
this PR adds the
--watch
flag tobuild
andpreview
, which watches your Wrangler project for changes and builds it when it's ready. It works for all project typesjavascript
-> watches the entry point inpackage.json
rust
-> watches the/src
directory, and the entry point inpackage.json
webpack
-> uses webpack's watching, which just worksWhen run in
--watch
mode,preview
hides the fiddle editor, since you would be using a local text editor instead.to test:
cargo install --force --debug --git https://github.com/xortive/wrangler --branch malonso/hotreload
Closes #235