Repository navigation
Custom widgets and Custom Dashboards read the app's mode, variant and palette - #23
Open
gustavo-aguiar wants to merge 13 commits into
Open
gustavo-aguiar wants to merge 13 commits into
gustavo-aguiar wants to merge 13 commits into
Conversation
A theme subscriber read the old appearance, because the theme store notified before the appearance changed. Both values now change first.
- A theme switch reaches the widget as its own `appearance` message. `userInformation` stays a handshake-only message, so `onSyncUserInformation` and effects on `useUserInformation()` do not run again. The store keeps the appearance in its own state, and a message without one keeps the last, as the root does. - The scheme the SDK wrote on the root is page state. A store that replaces another starts from it, a successor without the opt-in clears it, and the page takes it back as it leaves even after its store is destroyed. - The page ID is made on first use: some server runtimes refuse random values while a module loads. - The JS adapter runs each widget callback on its own and moves on before running them, so one that throws no longer blocks the others or repeats. `TagoIO.ready(null)` posts a bare `loaded` again.
This branch has not been deployed
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.
Feature · Custom widgets and Custom Dashboards read the app's mode, variant and palette
A custom widget cannot tell whether TagoRUN shows Light or Dark: the host sends no mode and pins the iframe to
color-scheme: normal, so an application built from custom widgets shows white pages next to a dark sidebar (tago-io/issues#1233). This PR is the SDK side: typed access to the appearance the host now sends, and an opt-in that lets the widget's page follow the app's color scheme.TagoIO.onSyncAppearance,useAppearance(){ mode, variant, palette }at start and on every change, with no reload.modeislightordark; with System it is what the OS resolves to. It lives in its ownappearancestate, so a theme switch leavesuserInformationandonSyncUserInformationalone. On a host that predates this it never arrives, anduseAppearance()staysnull.ready({ features: ["color-scheme"] })The SDK sets
color-schemeon the page root and reports it to the host, which gives the iframe the same scheme.light-dark(),prefers-color-scheme, system colors and form controls follow the app, and a page that paints no background stays transparent. Without the opt-in nothing changes.TagoDashboard.appearance,useDashboardAppearance()Reads
variantandpalettefromdashboard:theme; both readdefaulton an older host. A theme listener and an appearance listener both see the new values.In Admin,
variantis one of Admin's four variants. In a TagoRUN app it isdefaultor the ID of a variant the builder named.paletteis the base palette both share.TagoIO.on*A callback that throws is logged, and the callbacks after it still run, once per change. Before, it stopped
onStart,onRealtimeandonErroruntil the next change.How a widget follows the app's colors
Read the mode and apply your own colors. This works with or without the opt-in.
Let the iframe follow the app. Opt in, then style with
light-dark(). The SDK setscolor-schemeon the root for you, so do not declare one yourself.@media (prefers-color-scheme)inside the widget follows the app too, live switches included, in Chrome and Safari. A widget that loads the optionalcustom-widget.cssoverrides its white body and light form fields, as the JS README shows.Custom Dashboards read
{ mode, variant, palette }fromTagoDashboard.appearance(get,subscribe) oruseDashboardAppearance().Branch on
palettewhen only the colors matter: in a TagoRUN app,variantis the ID of a variant the builder named.Why
The host sends a later change as its own
appearancemessage rather than a seconduserInformation: widgets run one-time setup inonSyncUserInformation, and an older SDK ignores a message it does not know.userInformationtherefore arrives once after eachready(), as before, andWidgetState.appearancekeeps the last appearance the host sent.The host switches the iframe's scheme only after the page reports the scheme it put on its root. When the iframe and its root disagree, the browser paints an opaque canvas in the root's scheme, so a host that switched first would flash the widget in the old color. An opted-in
loadedmessage carries the scheme already on the root and a per-page ID. Onpagehidethe SDK takes its report back with that ID: Chrome delivers a message from a leaving page with nosource, so the host matches it by page ID and origin. A page the browser restores from its back-forward cache reports its scheme again.The scheme on the root belongs to the page, not to one store. A store that replaces another, after a provider remount or Fast Refresh, starts from the scheme on the root, and clears it when it does not opt in. The page takes its report back as it leaves even after
destroy(). The page ID is made on first use, because Cloudflare Workers refuse random values at module load. Aready()on a destroyed store does nothing untilinitialize().Limits that stay:
The transparent areas can show the canvas in the new color for one frame while the widget repaints.
Test plan
vp run build,vp check,vp run check:types,vp test run46 files and 662 tests pass, and so does CI. The committed
packages/js/distmatches a fresh build.color-scheme.test.ts,use-appearance.test.tsxA later
appearancemessage updates the appearance and leavesuserInformationas the handshake sent it. A repeat keeps the same object, and a message without one keeps the last.color-scheme.test.tsA store that replaces another starts from the scheme on the root; the page takes it back as it leaves after
destroy(); the page ID is made on the first opt-in; aready()afterdestroy()posts nothing and leaves the root alone; anas constoptions object type-checks.custom-widget.test.tsA throwing callback is logged and the rest still run once per change. A theme switch does not run
onSyncUserInformationagain.TagoIO.ready(null)posts a bareloaded, as it always has.appearance.test.ts,use-dashboard-appearance.test.tsxThe appearance starts from
?theme=on the URL, and inside either listener both values are new.Switching to Dark, Eye Comfort, then back to Light and Default:
onSyncUserInformationran once, andonSyncAppearanceran at start and after each switch. The opted-in iframe and root followed every switch; the widget without the opt-in stayednormal.prefers-color-schemein the iframe · Chrome and WebKit, no media emulationA cross-origin iframe on
darkreads dark under a light preference, one onlightreads light under a dark one, and switching the iframe's scheme fireschangeinside. Playwright's default light emulation forces every frame, which is why an earlier run read the OS.The opted-in widget's root and iframe are dark with a transparent background. The widget without the opt-in keeps
normaland its own white card. With the host onmain, nothing arrives.On load the opted-in iframe is never shown at
normal. On a switch the widget root flips 4 to 16 ms before the iframe.dark · eye-comfort · eye-comfortarrives, and the opt-in behaves as in TagoRUN.dashboard:themecarries{ theme, variant, palette }on ready and on a live switch, andTagoDashboard.appearancereads it.The host puts the iframe back to
normal.custom-widget.min.cssin ChromeWith the root on
dark, the stylesheet alone keeps a white body and light fields. With the README override, the body is transparent with white text, and the fields are dark.Screenshots
mainRisk (CIA)
Likelihood: 🟢 Low | Impact: 🟢 Low | Exposure: 🟢 Low
Related
Refs tago-io/issues#1233