From aefcd44a08b4c733319247d68b14b26787029464 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Wed, 7 Oct 2026 16:26:43 +0000 Subject: [PATCH] Point reflex component at the component template The custom components CLI was removed in 0.10, so every `reflex component` subcommand failed with "No such command 'component'. Did you mean 'compile'?" and no hint about where the workflow moved. Register a hidden `component` shim that accepts any subcommand and flags, logs that the command was removed in Reflex 0.10, points at the wrapping React docs and https://github.com/reflex-dev/component-template, and exits 1. `reflex component --help` prints the same pointer. The command stays out of `reflex --help`, and the plural typo `reflex components` now suggests it. Fixes #7490 Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01CEngePWmkuAQ31xWPb1Q9L --- news/+component-cli-shim.bugfix.md | 1 + reflex/reflex.py | 31 +++++++++++ tests/units/test_reflex.py | 88 +++++++++++++++++++++++++++++- 3 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 news/+component-cli-shim.bugfix.md diff --git a/news/+component-cli-shim.bugfix.md b/news/+component-cli-shim.bugfix.md new file mode 100644 index 00000000000..4437fe74ccf --- /dev/null +++ b/news/+component-cli-shim.bugfix.md @@ -0,0 +1 @@ +`reflex component` and its old subcommands now exit with a pointer to the wrapping React docs and the [component template](https://github.com/reflex-dev/component-template) instead of "No such command". diff --git a/reflex/reflex.py b/reflex/reflex.py index 6aad6461cb5..d2ea84aafde 100644 --- a/reflex/reflex.py +++ b/reflex/reflex.py @@ -1141,6 +1141,37 @@ def rename(new_name: str): rename_app(new_name, get_config().loglevel) +_COMPONENT_REMOVED = ( + "`reflex component` was removed in Reflex 0.10. Wrap React components " + "directly in your app (https://reflex.dev/docs/wrapping-react/overview/) " + "and start reusable component packages from the component template: " + "https://github.com/reflex-dev/component-template" +) + + +@cli.command( + name="component", + hidden=True, + help=_COMPONENT_REMOVED, + context_settings={"ignore_unknown_options": True}, +) +@click.argument("args", nargs=-1, type=click.UNPROCESSED) +def component(args: tuple[str, ...]): + """Point users of the removed component CLI at its replacement. + + Accepts any subcommand and flags so `reflex component init`, `build`, + `share`, and `install` all land here instead of a "No such command" error. + + Args: + args: The removed subcommand and its flags, ignored. + + Raises: + Exit: Always, after reporting where the component workflow moved. + """ + logger.error(_COMPONENT_REMOVED) + raise click.exceptions.Exit(1) + + cli.add_command( _LazyCommand( "deploy", diff --git a/tests/units/test_reflex.py b/tests/units/test_reflex.py index 04a088aacbe..376f755bdf5 100644 --- a/tests/units/test_reflex.py +++ b/tests/units/test_reflex.py @@ -74,6 +74,7 @@ def _run_cli_probe(probe: str) -> dict[str, object]: (["--help"], _CLI_STARTUP_DENIED_MODULES), (["--version"], _CLI_STARTUP_DENIED_MODULES), (["run", "--help"], _CLI_STARTUP_DENIED_MODULES), + (["component", "--help"], _CLI_STARTUP_DENIED_MODULES), ( ["deploy", "--help"], _CLI_STARTUP_DENIED_MODULES - {"reflex_cli.v2.deploy"}, @@ -87,6 +88,7 @@ def _run_cli_probe(probe: str) -> dict[str, object]: "help", "version", "run-help", + "component-help", "deploy-help", "cloud-help", ], @@ -227,9 +229,89 @@ def test_cloud_commands_registered(): } -def test_component_command_is_not_registered(): - """The custom components CLI has been removed.""" - assert "component" not in reflex.cli.commands +_COMPONENT_TEMPLATE_URL = "https://github.com/reflex-dev/component-template" + + +def test_component_command_is_hidden(): + """The removed component CLI keeps a shim that stays out of the listing.""" + assert reflex.cli.commands["component"].hidden + + result = click.testing.CliRunner().invoke(reflex.cli, ["--help"]) + + assert result.exit_code == 0 + listed = [line.split()[0] for line in result.output.splitlines() if line.strip()] + assert "component" not in listed + + +@pytest.mark.parametrize( + "args", + [ + [], + ["init"], + ["build"], + ["install", "reflex-example"], + ["share", "--no-interactive"], + ["--library-name", "reflex-example"], + ], +) +def test_component_command_points_to_template( + caplog: pytest.LogCaptureFixture, args: list[str] +): + """Every removed component subcommand reports where the workflow moved. + + Args: + caplog: The pytest log capture fixture. + args: The arguments a user of the old workflow passes. + """ + result = click.testing.CliRunner().invoke(reflex.cli.commands["component"], args) + + assert result.exit_code == 1 + assert _COMPONENT_TEMPLATE_URL in caplog.text + assert "No such option" not in result.output + assert "No such command" not in result.output + + +@pytest.mark.parametrize("args", [["--help"], ["init", "--help"]]) +def test_component_help_points_to_template( + monkeypatch: pytest.MonkeyPatch, args: list[str] +): + """Asking the removed component CLI for help prints the pointer. + + Args: + monkeypatch: The pytest monkeypatch fixture. + args: The help invocation after ``reflex component``. + """ + from reflex_base.utils import log + + # Registered so teardown restores the variable the CLI callback sets. + monkeypatch.setenv(log._MANAGED_ENV_VAR, "true") + try: + result = click.testing.CliRunner().invoke(reflex.cli, ["component", *args]) + finally: + log._reset() + + assert result.exit_code == 0, result.output + assert _COMPONENT_TEMPLATE_URL in result.output + + +def test_component_command_dispatches_from_cli(): + """``reflex component init`` reaches the shim instead of a usage error.""" + completed = subprocess.run( + [sys.executable, "-m", "reflex", "component", "init"], + capture_output=True, + text=True, + check=False, + timeout=30, + env={ + **os.environ, + "REFLEX_CHECK_LATEST_VERSION": "false", + "REFLEX_TELEMETRY_ENABLED": "false", + }, + ) + + assert completed.returncode == 1, completed.stderr + assert _COMPONENT_TEMPLATE_URL in completed.stderr + assert "No such command" not in completed.stderr def test_lazy_command_delegates_click_introspection(monkeypatch: pytest.MonkeyPatch):