Skip to content

Commit da3ee8e

Browse files
committed
refactor: gate entry.client.js skip on a plugin capability, not EmbedPlugin identity
Add `Plugin.provides_entry_client()` so any plugin can opt out of the framework's default `entry.client.js` write. `update_entry_client` now checks all registered plugins instead of importing `get_embed_plugin`, keeping the framework agnostic to which plugin owns the entry file.
1 parent f69684c commit da3ee8e

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

packages/reflex-base/src/reflex_base/plugins/base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ def post_build(self, **context: Unpack[PostBuildContext]) -> None:
153153
context: The context for the plugin.
154154
"""
155155

156+
def provides_entry_client(self) -> bool:
157+
"""Return whether this plugin emits its own ``entry.client.js``.
158+
159+
The framework calls this during ``setup_frontend`` to decide whether
160+
to skip its default ``entry.client.js`` write. Plugins that register
161+
a save task for the same path should return ``True`` so the framework
162+
write doesn't race with (or overwrite) theirs.
163+
164+
Returns:
165+
``True`` if the plugin owns ``entry.client.js`` for this build.
166+
"""
167+
return False
168+
156169
def update_env_json(
157170
self, **context: Unpack[CommonContext]
158171
) -> dict[str, Any] | None:

packages/reflex-base/src/reflex_base/plugins/embed.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,19 @@ def pre_compile(self, **context):
293293
_inject_vite_dev_preview(self.mount_target),
294294
)
295295

296+
def provides_entry_client(self) -> bool:
297+
"""Declare that EmbedPlugin emits its own ``entry.client.js``.
298+
299+
``pre_compile`` registers ``_embed_entry_task`` which writes the
300+
embed-aware entry template at ``constants.Embed.ENTRY_PATH``; the
301+
framework's default ``update_entry_client`` must skip this path to
302+
avoid stomping the embed entry on every compile.
303+
304+
Returns:
305+
Always ``True``.
306+
"""
307+
return True
308+
296309
def update_env_json(self, **context):
297310
"""Contribute the mount target so the embed entry can read it.
298311

reflex/utils/frontend_skeleton.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ def initialize_web_directory():
186186
def update_entry_client():
187187
"""Write ``.web/app/entry.client.js`` from the framework-mode template.
188188
189-
Skipped when ``EmbedPlugin`` is registered — the plugin emits the
190-
embed-aware variant via its own save task and overwriting it here would
191-
just be redone on the same compile.
189+
Skipped when any registered plugin reports ``provides_entry_client()`` —
190+
that plugin emits its own variant via a save task and overwriting it
191+
here would just be redone on the same compile.
192192
"""
193-
if get_embed_plugin() is not None:
193+
if any(p.provides_entry_client() for p in get_config().plugins):
194194
return
195195
write_file(
196196
get_web_dir() / constants.Embed.ENTRY_PATH,

tests/units/plugins/test_embed.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ def test_update_env_json_returns_mount_target():
5252
assert plugin.update_env_json() == {"MOUNT_TARGET": "#widget"}
5353

5454

55+
def test_provides_entry_client_is_true():
56+
plugin = EmbedPlugin(mount_target="#widget")
57+
assert plugin.provides_entry_client() is True
58+
59+
5560
def test_pre_compile_registers_save_tasks():
5661
plugin = EmbedPlugin(mount_target="#root")
5762
saved: list[tuple] = []

0 commit comments

Comments
 (0)