feat: add page_react() and template-mode page_react_html() - #208
Open
schloerke wants to merge 1 commit into
Open
feat: add page_react() and template-mode page_react_html()#208schloerke wants to merge 1 commit into
schloerke wants to merge 1 commit into
Conversation
Two coherent page modes replacing the halfway index.html fragment:
- page_react() (Python + R): zero-config server-composed page. Discovers
www/ui.js + www/ui.css, serves them as an mtime-versioned
HTMLDependency (cache-busted, unlike raw script tags), title defaults
to the app folder name, no body HTML — the client appends its own
mount container
- set_react_page() (Express): path now optional; with no args it uses
www/index.html when present, else falls back to page_react() discovery
(renderer-dep harvesting preserved via extracted helper)
- R page_react_html(): accepts a complete HTML document with a
{{ headContent() }} marker (htmltools::htmlTemplate); shinyreact deps
render at the marker via the new config_head_dep(). Fragments now
error with a pointer to page_react()
- Python page_react_html(): unchanged fragment behavior, documented as
blocked on an upstream py-shiny gap (App cannot accept a pre-rendered
document with extra dependencies)
schloerke
marked this pull request as ready for review
August 20, 2026 02:59
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.
Closes #205. Part of stack #209 (on top of #198 ← #197). Follows the two-mode design discussed for replacing the halfway index.html fragment.
Summary
Mode 1 —
page_react()(Python + R, new export). Zero-configuration server-composed page: no HTML file at all. Discoverswww/ui.jsandwww/ui.css(named for the ui.tsx pattern per #205 — the source entryui.tsxcompiles towww/ui.js, paired withui.css; the client entry is the ui, the server file is the app, and #204's rename discussion can flip the default later), serves them as an mtime-versionedHTMLDependency— so edits cache-bust, unlike raw<script src>tags in a hand-written HTML file. Title defaults to the app folder's name; extraHTMLDependencyargs pass through. The server emits no body HTML — the client appends its own mount container to<body>.Express follows:
set_react_page()'spathis now optional. With no args it useswww/index.htmlwhen present (existing behavior, so every current example keeps working), else falls back topage_react()discovery. Renderer-dependency harvesting works in both modes (extracted into_harvest_renderer_deps()).Mode 2 — R
page_react_html()accepts a real document. The file must be a complete HTML document containing a{{ headContent() }}marker (the kind a Vite build emits); it renders throughhtmltools::htmlTemplate(document_ = TRUE)with the shinyreact bundle and the#shinyreact-configtag injected at the marker via the newconfig_head_dep()(an href-less dependency carrying only head HTML). Fragment input now errors with a message pointing at the marker or atpage_react(). Assets the document references live inwww/and are served statically.Python
page_react_html()is deliberately unchanged (fragment mode):shiny.Apphas no way to accept a pre-rendered document with extra dependencies —HTMLTextDocumentis only used internally forui=Pathwith no injection hook (verified empirically:App(ui=HTMLTextDocument(...))fails onget_dependencies). The docstring documents the divergence and points users atpage_react(). Closing this needs an upstream py-shiny change.Examples intentionally untouched — #207 rewrites example 01 against
main; converting examples topage_react()should happen after it merges, avoiding conflicts.Verification
page_reactdefaults/title/css-skip/missing-js-warn/extra-deps/cwd-fallback;set_react_pageindex-precedence and discovery-fallback), pyright, ruff.<html>, config payload extraction, marker-missing error,page_reactsuite mirroring Python),R CMD check0 errors / 0 warnings / 0 notes. Tests render through acreateWebDependency-mimicking helper (helper-render.R) since standalonerenderDocumentcan't href file-based deps.