feat(notices): validated contract for host-supplied notices - #2666
Open
camielvs wants to merge 4 commits into
Open
feat(notices): validated contract for host-supplied notices#2666camielvs wants to merge 4 commits into
camielvs wants to merge 4 commits into
Conversation
Collaborator
Author
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Aug 26, 2026
🎩 PreviewA preview build has been created at: |
camielvs
commented
Aug 26, 2026
camielvs
commented
Aug 26, 2026
camielvs
commented
Aug 26, 2026
camielvs
commented
Aug 26, 2026
camielvs
commented
Aug 26, 2026
camielvs
commented
Aug 26, 2026
camielvs
force-pushed
the
banners-02-primitives
branch
from
August 26, 2026 23:45
dc471e3 to
ac56d12
Compare
camielvs
force-pushed
the
banners-03-contract
branch
from
August 26, 2026 23:45
a100783 to
eb0c6de
Compare
camielvs
force-pushed
the
banners-02-primitives
branch
from
August 27, 2026 01:18
ac56d12 to
3a5d8f1
Compare
camielvs
force-pushed
the
banners-03-contract
branch
from
August 27, 2026 01:18
d9ad21b to
4fb20f2
Compare
camielvs
commented
Aug 27, 2026
|
|
||
| declare global { | ||
| interface Window { | ||
| __TANGLE_NOTICE_SOURCE__?: unknown; |
Collaborator
Author
There was a problem hiding this comment.
This is typed to unknown but guarded by isNoticeSource, so only TangleNotice will work. TangleNotice is Tangle-UI's expectation of the blind contract and thus this is the shape the source will need to provide.
camielvs
marked this pull request as ready for review
August 28, 2026 00:02
camielvs
force-pushed
the
banners-02-primitives
branch
from
August 28, 2026 23:30
3a5d8f1 to
e204342
Compare
camielvs
force-pushed
the
banners-03-contract
branch
from
August 28, 2026 23:30
4fb20f2 to
189fa37
Compare
Adds the boundary an embedding page talks to: it may install a notice source on the window, and this module reads it defensively. Every field is validated and normalised, a malformed entry is dropped rather than trusted, and a source that declares an unsupported version is ignored wholesale. Headless and unreferenced — nothing renders these yet. Reviewable on its own, with the test file as the argument for what the boundary does and does not let through.
Collapse duplicate ids to the first occurrence and cap a snapshot at 20 entries, so a malformed host cannot produce duplicate React keys or unbounded per-render validation work. Freeze each banner rather than only the array — a mutated banner used to poison the signature cache for the life of the page, since the signature is computed before a consumer can reach the object. Declare __TANGLE_BANNER_SOURCE__ as unknown, which is what it is, and the cast in the test source helper disappears. Add BANNERS.md documenting the host-facing contract, in particular that the tangle:banner-source event is required after assigning the global. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Notices are the domain concept; banners are one of the two surfaces they are shown on. Renames the config module, its global and event, and the contract doc to match, before any host depends on the old names. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A notice with no title renders as a card whose first line is blank, and the publishing API this contract exists to serve rejects an empty title already. Requiring one here means InfoBox needs no change to support the case.
camielvs
changed the base branch from
banners-02-primitives
to
graphite-base/2666
August 28, 2026 23:51
camielvs
force-pushed
the
graphite-base/2666
branch
from
August 28, 2026 23:51
e204342 to
b525bf9
Compare
camielvs
force-pushed
the
banners-03-contract
branch
from
August 28, 2026 23:51
189fa37 to
46d176a
Compare
camielvs
changed the base branch from
graphite-base/2666
to
banners-01-markdown
August 28, 2026 23:51
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.

Why
The announcements this stack replaces are already host-installed:
AnnouncementBannersreadswindow.__TANGLE_ANNOUNCEMENTS__directly, andsrc/config/announcements.tsis nothing but thedeclare globalfor it. So the mechanism isn't new here — what's new is that it's validated, typed at the boundary asunknown, and can update after boot.The existing global has four problems, all of them things a host page can trigger today:
variant: announcement.variant ?? "info"passes any string through tovariantStyles[variant].container— a typo'd variant is aTypeErrorin render, and an entry with notitlerenders an empty banner.new Date(). Both a mutable global read and a clock read happen inside the component body, which is whyAnnouncementBanners.tsxcan't be enabled for the React Compiler.useState(getDismissedIds)snapshots once, and the global is read with no subscription — a host that installs or replaces its data after the app mounts is invisible until a reload. There's no event, so it's a race the host can't win.What you get
No behaviour change. This PR adds
src/config/notices.tsand its documentation; nothing imports it yet.__TANGLE_ANNOUNCEMENTS__and its banners are still the only thing on screen — they're replaced in #2667.With nothing installed the app shows nothing, exactly as it does today with the global unset.
src/config/NOTICES.mdis the reference for host authors.Reviewer notes
This is a trust boundary, which is where the code goes. The global is typed
unknownand everything is proven before it reaches a component: one type guard for the source, then per-field reads. The rules, all tested:versionmust be exactly1— a source declaring2is ignored wholesale, so a future contract can't half-render through this one.idrequired (a finite number is coerced);titlerequired and non-blank. An entry failing either is dropped rather than rendered empty.variantfalls back toinfofor anything unrecognised — this is the fix for thevariantStyles[variant]crash above.bodyis Markdown and renders throughUntrustedMarkdownfrom feat(markdown): shared Markdown renderer #2664. Whitespace is preserved because it's significant.action.urlmust be absolutehttp(s);javascript:and relative URLs drop the action and keep the notice.getSnapshotthat throws is treated as "no notices" rather than propagating.Two things worth a look because they're subtle rather than long:
Snapshot identity.
getSnapshotis called on every render, and a host that maps/spreads its array returns a new reference each time — which would loopuseSyncExternalStore. The store compares serialised content and returns the previous frozen array when it's unchanged. Tested with a rebuild-per-read source.The required event. The app subscribes when it mounts, which may be before the host has installed anything, so
subscribealone would race.tangle:notice-sourceis what tells the store to (re)bind — documented as required, tested for late installation, and safe to dispatch again after replacing the global. Without it the options are a silent race (today's behaviour) or blocking app boot on the host's fetch.Field-level differences from
Announcement:expiresAtis gone — a host that can update its snapshot expires a notice by dropping it, rather than shipping an expiry the app has to evaluate with a clock read in render.actionis added.id/title/body/variant/dismissiblecarry over.Where this sits