Skip to content

XAML: extract a shared dismissible-notification helper #213

Closed

Description

Follow-up from the PR #50 review (finding L4).

Three notification modules implement the same "show a notification with a Don't show again action, persist the dismissal in globalState" pattern with near-identical code:

  • src/xaml/csharpDevKitNotification.ts
  • src/xaml/degradedNotification.ts
  • src/xaml/projectRestoreNotification.ts

Each has its own state key handling, its own dismissal action wiring, and its own test file covering the same mechanics. A fourth such notification would mean a fourth copy.

Suggested work:

  • Extract a shared helper (e.g. showDismissibleNotification({ key, message, actions, memento })) that owns the globalState read/write and the "Don't show again" action.
  • Reduce the three modules to their message/action specifics.
  • Collapse the duplicated portions of the corresponding tests.

Activity

  1. added a commit that references this issue on Sep 8, 2026
    1fd5dc5
  2. chiaramooney commented on Sep 8, 2026

    @chiaramooney
    CollaboratorAuthor

    Implemented in PR #50 (1fd5dc5), but scoped differently than described here. Two corrections to the premise, since they changed what was worth building.

    projectRestoreNotification.ts does not belong in this list. It has no persisted dismissal, no globalState key, and no "Don't Show Again" action. It gates on a session-scoped Set of already-prompted project paths, which is deliberate: a restore prompt should return after a reload if packages are still missing. There is nothing to share, and folding it in would have meant giving it a persistence concept it should not have.

    degradedNotification.ts shares the flag but not the notification. It does persist a dismissal for the missing-runtime case, but the surrounding shape is different: a multi-action model (url / command / fallbackCommand / commandArg / showOutput) and suppression driven by cause transitions rather than dismissal alone. A generic showDismissibleNotification({ key, message, actions, memento }) would not have fit it, so the two call sites would have diverged immediately.

    So the shared part is narrower than the issue assumed: it is the persisted flag, not the presentation. What was actually duplicated is the globalState.get<boolean>(key, false) / globalState.update(key, true) pair, inlined at four sites in xamlLanguageService.ts, plus an ?? false / ?? Promise.resolve() fallback repeated wherever the ExtensionContext was optional.

    The fix extracts notificationDismissal(key, store) returning { isDismissed, dismiss() }, with a DismissalStore interface that globalState satisfies structurally, and routes the Dev Kit recommendation and the degraded runtime warning through it. Both keep their own message and action handling.

    One thing worth flagging for anyone adding tests here: test:unit lists test files explicitly rather than globbing, so a new test file runs zero tests until it is added to that list. The new file initially passed silently for exactly that reason. Extension suite is 1,119 passing (was 1,114).

    A fourth instance of the full pattern does exist, in extension.ts (winapp.manifestEditorNotificationDismissed), but it predates this PR and was left alone to keep the diff scoped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions