Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Add a new --live-reload parameter to the theme serve command #1871

Merged
merged 5 commits into from
Jan 17, 2022
Merged

Conversation

karreiro
Copy link
Contributor

@karreiro karreiro commented Dec 21, 2021

WHY are these changes introduced?

Some users prefer to fully the reload page (I) when a file is modified, instead of relying on the hot reload mechanism that updates sections individually (II). Also, other users have their own tooling for refreshing the page, so they need to deactivate any refresh mechanism (III) entirely.

This PR introduces the --live-reload with three modes: I) full-page, II) hot-reload (default), and III) off.
Screenshot 2022-01-14 at 10 40 49

WHAT is this pull request doing?

Main change

The new parameter (--live-reload) in the Theme::Command::Serve has three valid values:

  • hot-reload - it's the current approach
  • full-page - every time users perform a file change, the page is refreshed entirely
  • off - the page is never automatically updated (the hot-reload.js#connect function is never called)

The ShopifyCLI::Theme::DevServer::ReloadMode class works like an enum and validates the parameter value when the Serve command calls ReloadMode.get.

The mode value is injected into the page with the hot-reload.js at the ShopifyCLI::Theme::DevServer::HotReload level. So, the parameter controls how the page refreshes in the client-side.

ShopifyCLI::Context change

Following the error/try-this convention introduced here, this PR introduces the ShopifyCLI::Context.abort(error_message, help_message = nil) API.

Now the abort API has an optional help message, which appears in the Try this frame.

How to test your changes?

Run shopify theme serve --live-reload=<MODE> with different reload modes and notice how the page behaves differently for each one:

  • shopify theme serve --live-reload=hot-reload
    hot-reload

  • shopify theme serve --live-reload=full-page
    full

  • shopify theme serve --live-reload=off
    off

  • shopify theme serve (fast as the default)
    default

  • shopify theme serve --live-reload=other

Screenshot 2022-01-14 at 10 41 13

Post-release steps

Update documentation with shopify theme serve parameters: shopify.dev/themes/tools/cli/theme-commands#serve.

Update checklist

  • I've added a CHANGELOG entry for this PR (if the change is public-facing)
  • I've considered possible cross-platform impacts (Mac, Linux, Windows).
  • I've left the version number as is (we'll handle incrementing this when releasing).
  • I've included any post-release steps in the section above.

@karreiro karreiro linked an issue Jan 5, 2022 that may be closed by this pull request
@karreiro
Copy link
Contributor Author

👋 Hi, @MeredithCastile! :)

This PR introduces a new flag for the theme serve command, the --live-reload-mode=MODE.

Currently, the live-reload mechanism has only a single mode (fast), so when partners change some file, theme serve shows the preview by:

  • refreshing the entire page (automatically) when it's impossible to update components individually; or
  • updating the page components individually with the edited ones.

However, some advanced users prefer to deactivate the mechanism above because they have custom tooling to auto-refresh the page. Other partners prefer to refresh the entire page always.

For handling these needs, the --live-reload-mode=MODE flag has 3 modes:

  • fast - it's the current approach (default)
  • full - every time users change a file, the page is refreshed entirely
  • none - the page is never automatically updated, and the live reload is inactive

I personally like this terminology, but I'm not sure if this is the best one we can achieve for partners. What do you think about it? :)

Thanks! 🚀

@MeredithCastile
Copy link
Contributor

Yes, those seem okay to me. You might consider exploring whether the word "mode" is necessary. I go back and forth on that.

You might consider, too, changing "full" to "full-page." To make it more intuitively graspable.

Suggestion, then:


theme serve --live-reload=fast
theme serve --live-reload=full-page
theme serve --live-reload=off

As always, we should have this in our help and documentation.

Rename `full` to `full-page`
Rename `none` to `off`
@karreiro karreiro changed the title Add a new --live-reload-mode parameter to the theme serve command Add a new --live-reload parameter to the theme serve command Jan 13, 2022
@karreiro karreiro marked this pull request as ready for review January 13, 2022 16:33
@karreiro karreiro requested review from a team, pepicrft, amcaplan and macournoyer and removed request for a team January 13, 2022 16:33
Copy link
Contributor

@macournoyer macournoyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks right to me, other than comments.

Not too sure if we should rename "fast" to "hot reload". The feature is mentioned in the doc as "hot reload": https://shopify.dev/themes/tools/cli/theme-commands#serve. What do you think?

lib/shopify_cli/theme/dev_server/reload_mode.rb Outdated Show resolved Hide resolved
lib/shopify_cli/theme/dev_server/hot-reload.js Outdated Show resolved Hide resolved
lib/project_types/theme/messages/messages.rb Outdated Show resolved Hide resolved
@karreiro
Copy link
Contributor Author

karreiro commented Jan 14, 2022

Thanks for the review, @macournoyer!

Great suggestions, "hot reload" is more expressive than "fast"! I've updated the PR description and applied the changes/fixes in a new commit.

Thanks!

@karreiro karreiro merged commit b10ce18 into main Jan 17, 2022
@karreiro karreiro deleted the fix-1547 branch January 17, 2022 13:21
@notrealdev
Copy link

I have an error on Shopify 2.12

Imgur

@karreiro
Copy link
Contributor Author

karreiro commented Feb 25, 2022

Thanks a lot for reporting this and for sharing the stack, @notrealdev!

You may work around this issue by using the --live-reload flag without the equal sign, like this:

shopify theme serve --live-reload off

Still, I've just opened a PR fixing this issue #2092, so you will be able to use the equal sign again in the next CLI version.

We've done extensive work in the parameters parser to support glob parameters (#2066), which recently introduced that issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Disable hot-reload
4 participants