Skip to content

Draft: Persist rich tool displays with htmltools - #316

Draft
cpsievert wants to merge 3 commits into
mainfrom
draft/use-htmltools-serialized-html
Draft

Draft: Persist rich tool displays with htmltools#316
cpsievert wants to merge 3 commits into
mainfrom
draft/use-htmltools-serialized-html

Conversation

@cpsievert

@cpsievert cpsievert commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Why this matters

The immediate serialization fix deliberately keeps shinychat's existing dependency dictionaries so it can ship without waiting for another package release. Those dictionaries are suitable for the browser, but they omit the dependency source needed to register local CSS and JavaScript in a later session.

With the RenderedHTML value object proposed in posit-dev/py-htmltools#123, the result of render() owns its source-preserving durable representation. Shinychat can use that public boundary instead of maintaining a parallel dependency schema.

What changes

  • Delegate new rich-display writes to htmltools.serialize_html(), the convenience API over RenderedHTML.to_serialized().
  • Restore new values with htmltools.deserialize_html().
  • Keep a small reader for dependency dictionaries written by older shinychat versions.
  • Remove session behavior from deserialization; Shiny still registers and rewrites dependencies when UI is processed for the browser.
  • Construct RenderedHTML through its public constructor so the code works with both the current TypedDict and the proposed value object.

Compatibility

Old records remain readable. Their HTML and previously resolved dependency URLs are preserved, but local sources cannot be recovered because older shinychat versions did not store them. Once an old value is loaded and written again, it uses the new schema.

Verification

  • uv run --no-sync pytest -q --ignore=pkg-py/tests/playwright (431 passed)
  • The fresh-app regression verifies that a restored local dependency mounts at /lib/my-dep-1.0.
  • uv run --no-sync ruff check pkg-py --config pyproject.toml
  • uv run --no-sync pyright
  • Source distribution and wheel build

The repository-wide Ruff format check still reports the inherited formatting difference in pkg-py/tests/playwright/chat/aside_responsive/test_aside_responsive.py.

Before marking ready

@cpsievert
cpsievert force-pushed the draft/use-htmltools-serialized-html branch from a684b12 to cb12177 Compare August 14, 2026 17:10
Base automatically changed from refactor/python-tool-display-json-fallback to main August 14, 2026 17:20
@gadenbuie
gadenbuie force-pushed the draft/use-htmltools-serialized-html branch from cb12177 to 1246209 Compare August 14, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant