Fix livereload default broken by Click 8.3+#4111
Open
zf-unity wants to merge 1 commit into
Open
Conversation
Click 8.3 changed how `default=` is resolved when the same parameter is declared with two `flag_value` options. The previous form left the effective default as `False`, so `mkdocs serve` (no flags) silently ran without livereload — no `server.watch()` calls, no rebuild on edit, and no script injection into served HTML. Replace the dual-decorator pair with a single `--livereload/--no-livereload` boolean option carrying `default=True`. Both flag names continue to work and the help text is preserved on the visible `--no-livereload` form. Fixes mkdocs#4032 Fixes mkdocs#4055
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mkdocs serve(with no flags) silently runs without livereload when Click ≥ 8.3 is installed. Symptoms:Watching paths for changes:log line at startup.Detected file changes/Building documentation....<script>, so the browser never refreshes.Root cause
The
servecommand declares the livereload flag with two separate@click.optiondecorators sharing the same parameter name and usingflag_value:Up to Click 8.2.1 this resolved the parameter's default to
True. Click 8.3 (pallets/click#3084) changed the resolution rules so the first decorator wins the default, leavinglivereload=Falsewhen no flag is passed.serve.pythen skips the entireif livereload:block (noserver.watch(), no observer, no<script>injection).Reproduction:
Fix
Collapse the two
flag_valueoptions into a single boolean option:@click.option('--livereload/--no-livereload', 'livereload', default=True, help=no_reload_help)This is the canonical Click way to express a "yes/no" boolean flag and is robust to the 8.3 resolution change. Both
--livereloadand--no-livereloadcontinue to work; the help text remains attached to the visible secondary form.Fixes #4032
Fixes #4055
Test plan
mkdocs serve(no flags) showsWatching paths for changes: 'docs', 'mkdocs.yml'on startup.FileModifiedEvent→Detected file changes→Building documentation....livereload(epoch, request_id)<script>.mkdocs serve --no-livereloadcontinues to disable the watcher and skip script injection.mkdocs serve --livereload(explicit) behaves the same as the new default.mkdocs serve --helpdocuments--livereload / --no-livereloadwith the existing help string.