# Shared UI notifications
The application shell loads `wwwroot/js/notifications.js` and `css/notifications.css` once, outside replaceable page/panel content. No additional library is required.
```js
PlotDirector.toast.success('Changes saved');
PlotDirector.toast.info('Export completed');
PlotDirector.toast.warning('Word connection interrupted');
PlotDirector.toast.error('Unable to save changes');
```
Use success for completed user actions, info for meaningful background completion, warning for attention required, and error for unsuccessful operations. Routine successful background sync, paragraph changes and navigation should stay silent. Keep progress indicators, field validation, destructive confirmations, persistent connection state, and substantial recovery instructions in their existing workflow.
Success/info dismiss after six seconds. Warning/error remain until dismissed. An optional second argument `{ duration: 10000 }` overrides the duration; zero means manual dismissal. The returned function dismisses that toast. Hover/focus pauses auto dismissal; leaving restarts the duration. Close buttons work with the keyboard and Escape dismisses the focused toast. Notifications never take focus. Status/alert roles announce messages; labels convey categories without relying on colour.
Identical category/text is suppressed while visible and for five seconds after its last accepted display. At most four toasts appear; the oldest is removed on overflow. This is transient feedback, never the sole record of an ongoing problem.
Pages and dynamically loaded partial scripts use the same API without creating hosts or subscriptions. For server flash messages, retain the existing consuming TempData read and emit Razor-encoded text:
```cshtml
@if (TempData["SaveMessage"] is string message)
{
@message
}
```
The singleton observer consumes and removes markers, including newly inserted partials. Do not use `TempData.Peek`/`Keep` for these messages or cache/reinsert consumed flash fragments. Messages are plain text, never HTML. The service and CSS use the same shell in browser and installed PWA, including viewport/safe-area sizing and theme variables.
## Bounded migration inventory
- Shared archive/import information; book archive/manuscript information; chapter archive/update messages.
- Character image success, relationship/update information; location list/detail success; floor plan and metric messages; collaborator success; native review save confirmation.
- Word: one interruption warning after a connected session, one recovery info message; explicit sync-request errors also surface as toasts, retaining detailed inline feedback. The separately hosted Office Companion loads the same service and reports a sync failure once until recovery. No initial-offline warning and no routine successful sync/navigation toast.
- Retained: archive/location/image/collaboration errors and recovery instructions; Word persistent status and sync progress/review instructions; onboarding and import-result workflows; scenario warnings; all validation and confirmation dialogs.
Other feature-specific/admin banners and scripts remain future cleanup opportunities. Do not broaden migration without reviewing their workflow semantics.
## Focused verification
Run `node PlotLine.Tests/Browser/shared-notifications.cjs` from the repository root. It uses production assets in isolated Chromium documents with no application/database writes, testing all categories, plain-text rendering, focus preservation, bounded display, dismissal, duplicate suppression, partial markers and repeated script loading, and native Word interruption/recovery events. Both ordinary and simulated standalone presentation are covered; physical installed-PWA and Word acceptance are separate from this check.
Implementation validation (2026-11-21): solution build and the full executable regression harness passed; focused browser checks passed. Word transport, debounce, capture, paragraph identity, navigation, and native Windows components were not changed.
## Completed Word/Writer cleanup (2026-11-21)
All three web shells (application, embedded writing window, Office Companion) now load the same toast service and Word presentation adapter. `word-notifications.js` consumes existing native/Office presence and Writer status events; it does not fetch, poll, schedule, capture or analyse anything. `requested(lease, requestId)` records only a notification correlation. A manual paragraph success requires the matching request and newer verified positions; a chapter success requires the matching accepted chapter transfer. Unrelated receipts cannot claim success.
| Previous presentation/message | Result |
| --- | --- |
| Writer command paragraph, echoed into the ribbon | Command diagnostics moved inside Connection and update options. Ribbon now shows concise persistent manuscript state, with full freshness explanation in its title. |
| Live announcements from Writer connection/command/ribbon, native sync feedback, Reader update status | Removed competing routine live regions. Shared toast status/alert regions announce meaningful outcomes. Persistent text remains readable. |
| Changes detected / Checking changes / Synchronising chapter / Up to date | Never toast or open a web alert. Incoming chapter progress is confined to persistent state/details. These exact four literals were not hard-coded web transient messages in the checked revision. Native ribbon/tray labels such as Changes found, Checking, Synchronising and Up to date remain persistent and unchanged. |
| Office document-message area (reading/resolving/scanning/current-scene updates and diagnostics) | Moved into Manuscript details; routine updates no longer occupy the main notification area. Existing sync indicator remains visible. |
| Native paragraph transfer failed/cancelled, chapter Needs review | One shared error/warning per failure state until accepted recovery; a warning can escalate to an error. Persistent freshness/details remain. |
| Manual Writer check request failure / accepted check | Error toast on request failure; success toast only for matching accepted completion. Request acknowledgement/checking is silent. |
| Native connection dialog sync/repair request errors, timeout, accepted result | Request errors/timeout toast; matching accepted manual completion uses the central adapter. Existing progress and recovery instructions remain beside the controls. |
| Word connection lost/restored (native and Office) | Consolidated transition notifications; no initial-offline toast, no repeated reconnect warning. Embedded shell now supports these too. |
| Office Sync failed / Synced / Syncing... / waiting for typing | Failure toast once plus visible failed status. Automatic completion clears failure silently. Explicit manual success toasts; in-progress/waiting text stays in the indicator. |
| Word confirmed navigation (including paragraph start), failed/expired/mismatched/timed-out navigation | Shared success/error toast for the existing manual outcome; detailed command record stays inside options. Receipt processing, wait/confirmation timing and cancellation are unchanged. |
| Manuscript linked / structure imported / Characters created / marker save confirmed or already present | Shared success toast replaces document-message completion. Binding labels, first-run step results/counts and save-required instructions remain where needed. |
| Scene links saved successfully / manual chapter-scene linking or ID attachment / manuscript unlinked-cleaned | Shared success toast; redundant link-status completion text removed. |
| Manual scene-link save, chapter/scene create-link/ID attachment, first-run link/import/character creation, marker update, diagnostics scan and unlink/cleanup failures | Shared error toast; actionable error details and existing recovery/confirmation workflows retained. |
| Reader Chapter updated / automatic checking and pending accepted updates | Background completion stays silent in persistent status. Explicit Apply update success toasts. Update-read failure toasts once until recovery; persistent retry/sign-in text remains. |
Retained deliberately: Word unsaved/unverified/mapping/selection/capability warnings; persistent connection/freshness/progress; first-run scan/preview/build and marker-save review instructions; detailed cleanup recovery; destructive unlink/cleanup confirmations; Context/Intent follow status and substantial unavailable-content explanations; native import conflict/review/result summaries and validation. `native-companion-review.js` only selects the submitted session; it has no competing notification mechanism. The native workspace connection label remains persistent and feeds the shared connection presentation. No Windows agent, VSTO ribbon, native modal maintenance/troubleshooting dialog, transport, debounce, capture, paragraph identity, navigation processing or analysis was changed.
Focused checks: `shared-notifications.cjs`, `word-toast-outcomes.cjs`, `word-toast-paths.cjs` (actual Razor Writer/manual check/navigation/native-dialog form paths), `writer-word-notifications.cjs` (existing correlated navigation timing/race regression), `reader-word-freshness.cjs`, and `word-companion-regressions.cjs`. The existing navigation test opens the newly collapsed command diagnostics before checking them; its timing/correlation assertions are retained. Office adapter tests execute the production presentation setter without starting Office. Browser and simulated standalone checks do not physically verify Word, native Windows UI, or a genuinely installed PWA.
## Position preference
Toasts default to **Bottom left**. Open the account menu → **Customise PlotDirector…** → **Notifications** → **Toast position** to choose **Bottom left** or **Bottom right**. Position changes apply and save immediately, independently of the toolbar Save/Cancel buttons. No top positions are supported.
The account's `AppUser.ToastPosition` is read through `UserAppearance_Get` and saved through `UserAppearance_SaveToastPosition` (`295_UserToastPosition.sql`), using the existing appearance repository and authenticated, antiforgery-protected `/Appearance/ToastPosition` action. All three shell hosts render that server preference, including fresh sessions and installed PWA use. A user-scoped localStorage event relays confirmed changes to other open same-origin windows; localStorage does not override the database on a new page. Failed saves restore the previous position.
Toasts stack upwards in arrival order across notification types. Safe-area margins apply on both sides and below; narrow viewports reserve additional space above bottom controls. A shell with additional fixed controls can increase `--pd-toast-bottom-offset`. Existing toast types, timing, deduplication, dismissal and announcements are unchanged. Run `PlotLine.Tests/Browser/toast-position.cjs` against the isolated toolbar browser fixture for position, immediate application, persistence, failure rollback, cross-window and narrow/standalone checks.
## Word incident and current-chapter authority correction
The heartbeat's `ChapterIssue` means the native reader's `FailedRevision` matches its current Word revision. It is not an accepted-checkpoint status. Previously `NativePresenceController` copied it into a synthetic cached `ChapterProgress=Needs review`, which remained after a clear heartbeat. That overwrite is removed: the current reading flag and server checking/acceptance progress remain separate. Reading-state transitions are logged without manuscript prose; native diagnostics are preserved. Companion Settings → Advanced mode → Troubleshooting exposes Connection and document diagnostics and Open logs folder. Do not promise that clicking Synchronise repairs a reader failure or constitutes chapter acceptance.
`WriterWord_ChapterVerification` (migration 296) is SELECT-only. The selected chapter is verified only when its accepted checkpoint matches an unexpired validation for the authorised user, manuscript, session, Word revision, content hash, identity hash and mapping hash. Needs-review checkpoints stay needs-review. No canonical data or flags are changed. A historical content-acceptance timestamp is labelled as historical; current validation has its own timestamp. Document-wide progress, reading failure and current-chapter verification are distinct; another chapter's failure does not falsely invalidate a verified selected chapter.
Word failure receipts live in the bounded, account-scoped `plotdirector.wordIncidents.v1.` localStorage journal. Reading, transfer and document-checking have separate incident identities. A displayed incident is remembered before announcement, so dismissal and navigation cannot reannounce it. Changed manuscript/revision/request/failure details or a new failure after an explicit resolved transition can notify again, subject to normal shared toast deduplication. Current-book scoping prevents an unrelated open document's failure from interrupting that workspace. Transfer acceptance does not clear a reading incident; an explicit cleared reading flag does. Actual successful checking clears its own incident. Resolution removes an obsolete visible toast, including across same-origin windows. Persistent details remain accessible even when no toast is shown.
Focused checks: `word-state-lifecycle.cjs` tests disposable Book/Writer notification-shell lifetimes, dismissal, repeated polling, changed failures, independent recovery and scoping; `word-ribbon-verification.cjs` tests the real Writer Razor ribbon switching selected chapters and refusing sync acknowledgements as verification evidence. Existing manual-transfer and navigation/Reader regressions remain applicable. Development read-only checks confirmed a historical 15 November checkpoint with matching 21 November session validation; wrong-revision evidence is unverified and unauthorised users receive no rows. Canonical payload hashes are checked before/after deployment. No import, rescan, replay, flag reset or native Windows change is part of this correction.