Repository navigation
Give a page script's widget view one lifecycle helper, whileInterfaceConnected - #4004
Merged
Merged
Conversation
…Connected Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
approved these changes
Oct 25, 2026
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.
A playground's page script repeated about 15 lines of lifecycle in four examples (
alert-thresholds,code-comparison,data-explorer,notification-playground) and in the playground's author instructions, which #3952 made show the script whole: wait forPAGE_INTERFACEand hold presentation withpresent(), declare slices and the instruction provider once per lifetime behind a flag, subscribe on each connection, reconnect at once, and ignore thePAGE_INTERFACEa revision applied in place dispatches again. This gives that lifecycle one owner and cuts every copy over to it.declare()runs once, before the firstconnect(signal); the first connection waits forPAGE_INTERFACEand holds presentation untilconnecthas run, a reconnection runs it at once, and the cleanupconnectreturns runs as the element leaves.Where it lives. The brief asked for a helper in the playground package, but a page script can't reach one:
revision_artifact.resolve_dependencyadmits only/page/modules andPUBLIC_MODULES(widget-api.jsand Floating UI) from authored code, and a method onlf-playgroundcan't be called before the widget upgrades, which is the wait the helper exists to hide. The helper is generic instead: it names no widget, so it lives in the runtime besidePAGE_INTERFACE(runtime/presentation.js) and is exported fromwidget-api.js.module-authoring.md, "Startup and presentation", documents it, and the playground's author instructions show the short form. Making package modules importable from pages would be a new public-module mechanism, which this doesn't need.No protocol bump. The change adds a
widget-api.jsexport and removes or changes none;layer-registry.md, "Page protocol", keeps the number for additive public APIs, and pages vendored earlier keep running their long form against the same playground methods.tests/runtime/interface-connected.test.mjscovers the lifecycle: one declaration, connection at the page interface, none again on a later one, cleanup on departure, an immediate reconnection, and a view that left before the page interface. Removing the "already connected" guard fails it.Checks:
pnpm run test:runtime(561 pass),pnpm run check:browser, pre-commit;tests/browser/widgets/test_playgrounds.py -k "control_written_in_the_preview or rail_stays_in_view or short_workspace_shows_more or code_reader_design_comment or notification_playground or undoing_a_playground_choice"(7 pass);leaf-dev probeon the four examples shows each provider's instruction, the contributors' paint and no console errors. Nothing visible changes, so no stills or preview refresh.