[PR #7935] [MERGED] refactor(client): shared AppBanner and banner host (#7923 prep) #8011

Closed
opened 2026-10-24 04:09:38 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7935
Author: @Gunterlie
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/21/2026
Merged by: @Gunterlie

Base: staging ← Head: chore/app-banner-7923


📝 Commits (5)

  • 18f5570 refactor(client): replace CSRF origin banner with shared AppBanner host
  • 7c7f47e refactor(client): overlay AppBanner instead of re-laying out the shell
  • dfa0245 docs(client): fix banner hook extension in directory map
  • 2beaa33 fix(client): give the CSRF banner its own Copy key
  • 4647dbf fix(client): sort CSRF banner Copy key

📊 Changes

7 files changed (+248 additions, -226 deletions)

View changed files

📝 packages/client/.instructions.md (+1 -1)
📝 packages/client/src/App.tsx (+2 -2)
➖ packages/client/src/components/diagnostics/CsrfOriginWarningBanner.tsx (+0 -220)
➕ packages/client/src/components/diagnostics/use-csrf-origin-banner.tsx (+114 -0)
➕ packages/client/src/components/layout/AppBannerHost.tsx (+46 -0)
➕ packages/client/src/components/ui/AppBanner.tsx (+81 -0)
📝 packages/client/src/localization/locales/en.json (+4 -3)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.

Linked issue

Part of #7923 and #7911 (parent #7909). Prep slice; no new banners are added here.

Why this change

#7911 (access warning on every page) and #7923 (owner notices) both need to show a banner across the whole app. The only banner today, CsrfOriginWarningBanner, is a one-off: inline styles, hard-coded colours, always red, always assertive, session-only dismissal. Adding two more one-offs would mean three banners that can stack on top of each other and each shout at screen readers. This PR turns it into one shared banner and one mount point that shows only the most severe banner at a time, then moves the CSRF warning onto it with the same behaviour.

What changed

  • New components/ui/AppBanner.tsx: shared banner with warning and critical looks, theme classes, collapsed "Details" (native <details>), 44 px targets, safe-area top padding. role="alert" (critical) / role="status" (warning) wraps only title + body, so Details and Copy are not announced.
  • New components/layout/AppBannerHost.tsx: single mount point (where the CSRF banner was in App.tsx); picks the most severe candidate. Dismissal per banner id — warning in localStorage, critical in sessionStorage (same as before for CSRF).
  • New components/diagnostics/use-csrf-origin-banner.tsx: the old probe logic, returns a critical banner candidate. Copy button unchanged (now via copyToClipboard, timer cleared on unmount). The long "auto-trusted ranges" text moved into Details.
  • Deleted CsrfOriginWarningBanner.tsx. Existing ui.diagnostics.csrforiginwarningbanner.* keys reused; two new English keys (ui.app.banner.details, ui.app.banner.dismiss); two keys that lost their only user removed.
  • Placement stays as on staging: fixed at the top above the app, capped at half the viewport height. A first version pushed the app down instead, but that broke FloatingWindow positions and the iOS keyboard layout, which use viewport coordinates. Push layout can come later with a measured banner height if a banner needs it.
  • ponytail: the warning look uses Tailwind amber-*, because --warning is read in the CSS but never defined in any theme. Upgrade path: define a --warning theme token and switch the banner to it.

Validation

  • pnpm check (full) and pnpm localization:check pass locally.

  • git grep CsrfOriginWarningBanner returns nothing.

  • Opus review (fix-then-ship) and local CodeRabbit (2 findings: copy timer, amber colours) — all addressed except the token, see the ponytail note above.

  • Local CodeRabbit rerun, 4 findings: wrong file extension in .instructions.md (fixed); amber colours (see ponytail note). Not changed, with reasons:

    • Copy button reuses lorebook.editor.batch.copy and the fragmented csrforiginwarningbanner.* sentence keys: both are unchanged from staging. Renaming them would drop existing community translations; regrouping the CSRF copy into whole-sentence keys belongs in a separate localization change.
    • Critical banner uses --destructive, as the old banner did; no change in colour behaviour.
  • pnpm check passes locally

  • Container (Docker / Podman) built and ran without issue

  • Ran the app, clicked through the changes manually

  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)

  • Above manual verification completed (describe below)

  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Manually verify the CSRF banner appears when opening Marinara from an untrusted origin (e.g. a public IP not in CSRF_TRUSTED_ORIGINS), in light and dark theme.
  • Manually verify Copy copies the CSRF_TRUSTED_ORIGINS=… line and shows "Copied".
  • Manually verify Details opens and closes, and dismissing hides the banner until the next session.
  • Manually verify with a screen reader that only the title and text are announced.
  • Manually verify on a notched iPhone / installed PWA that the banner clears the notch.
  • Manually verify that with no banner the app looks exactly as on staging.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

Screenshots at 390 / 768 / 1440 px in light and dark, collapsed and expanded, were taken locally with the probe stubbed to an untrusted origin. They are not attached here (the CLI cannot upload images); a maintainer can add them, or the manual checks above cover the same states.

Summary by CodeRabbit

  • New Features

    • Added a unified app-wide banner system with warning and critical styles, expandable details, optional actions, and dismissal controls.
    • Added clearer CSRF origin diagnostics, including the rejected origin, configuration guidance, trusted network ranges, and a copyable configuration value.
    • Banners now prioritize the highest-severity active message and remember dismissals appropriately.
  • Bug Fixes

    • Improved handling of unavailable CSRF status checks and browser storage, preventing unnecessary banners and preserving in-session dismissal.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7935 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@Gunterlie](https://github.com/Gunterlie) **Base:** `staging` ← **Head:** `chore/app-banner-7923` --- ### 📝 Commits (5) - [`18f5570`](https://github.com/Pasta-Devs/Marinara-Engine/commit/18f5570c8af63b25b86b421deebae89f5b0cc1da) refactor(client): replace CSRF origin banner with shared AppBanner host - [`7c7f47e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7c7f47eeb80f77832c6af1173f9e12cc06ed36f8) refactor(client): overlay AppBanner instead of re-laying out the shell - [`dfa0245`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dfa02452f5f47c024f88af641b5ba5a9fc5f9102) docs(client): fix banner hook extension in directory map - [`2beaa33`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2beaa33be4277c13fa6dcd8170b7b3ec3615a5d4) fix(client): give the CSRF banner its own Copy key - [`4647dbf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4647dbfe4c06b5d3c02d2395cf15627916863c9d) fix(client): sort CSRF banner Copy key ### 📊 Changes **7 files changed** (+248 additions, -226 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/.instructions.md` (+1 -1) 📝 `packages/client/src/App.tsx` (+2 -2) ➖ `packages/client/src/components/diagnostics/CsrfOriginWarningBanner.tsx` (+0 -220) ➕ `packages/client/src/components/diagnostics/use-csrf-origin-banner.tsx` (+114 -0) ➕ `packages/client/src/components/layout/AppBannerHost.tsx` (+46 -0) ➕ `packages/client/src/components/ui/AppBanner.tsx` (+81 -0) 📝 `packages/client/src/localization/locales/en.json` (+4 -3) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. ## Linked issue Part of #7923 and #7911 (parent #7909). Prep slice; no new banners are added here. ## Why this change #7911 (access warning on every page) and #7923 (owner notices) both need to show a banner across the whole app. The only banner today, `CsrfOriginWarningBanner`, is a one-off: inline styles, hard-coded colours, always red, always assertive, session-only dismissal. Adding two more one-offs would mean three banners that can stack on top of each other and each shout at screen readers. This PR turns it into one shared banner and one mount point that shows only the most severe banner at a time, then moves the CSRF warning onto it with the same behaviour. ## What changed - New `components/ui/AppBanner.tsx`: shared banner with `warning` and `critical` looks, theme classes, collapsed "Details" (native `<details>`), 44 px targets, safe-area top padding. `role="alert"` (critical) / `role="status"` (warning) wraps only title + body, so Details and Copy are not announced. - New `components/layout/AppBannerHost.tsx`: single mount point (where the CSRF banner was in `App.tsx`); picks the most severe candidate. Dismissal per banner id — warning in `localStorage`, critical in `sessionStorage` (same as before for CSRF). - New `components/diagnostics/use-csrf-origin-banner.tsx`: the old probe logic, returns a critical banner candidate. Copy button unchanged (now via `copyToClipboard`, timer cleared on unmount). The long "auto-trusted ranges" text moved into Details. - Deleted `CsrfOriginWarningBanner.tsx`. Existing `ui.diagnostics.csrforiginwarningbanner.*` keys reused; two new English keys (`ui.app.banner.details`, `ui.app.banner.dismiss`); two keys that lost their only user removed. - Placement stays as on staging: fixed at the top above the app, capped at half the viewport height. A first version pushed the app down instead, but that broke `FloatingWindow` positions and the iOS keyboard layout, which use viewport coordinates. Push layout can come later with a measured banner height if a banner needs it. - ponytail: the warning look uses Tailwind `amber-*`, because `--warning` is read in the CSS but never defined in any theme. Upgrade path: define a `--warning` theme token and switch the banner to it. ## Validation - `pnpm check` (full) and `pnpm localization:check` pass locally. - `git grep CsrfOriginWarningBanner` returns nothing. - Opus review (fix-then-ship) and local CodeRabbit (2 findings: copy timer, amber colours) — all addressed except the token, see the ponytail note above. - Local CodeRabbit rerun, 4 findings: wrong file extension in `.instructions.md` (fixed); amber colours (see ponytail note). Not changed, with reasons: - Copy button reuses `lorebook.editor.batch.copy` and the fragmented `csrforiginwarningbanner.*` sentence keys: both are unchanged from staging. Renaming them would drop existing community translations; regrouping the CSRF copy into whole-sentence keys belongs in a separate localization change. - Critical banner uses `--destructive`, as the old banner did; no change in colour behaviour. - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Manually verify the CSRF banner appears when opening Marinara from an untrusted origin (e.g. a public IP not in `CSRF_TRUSTED_ORIGINS`), in light and dark theme. - Manually verify Copy copies the `CSRF_TRUSTED_ORIGINS=…` line and shows "Copied". - Manually verify Details opens and closes, and dismissing hides the banner until the next session. - Manually verify with a screen reader that only the title and text are announced. - Manually verify on a notched iPhone / installed PWA that the banner clears the notch. - Manually verify that with no banner the app looks exactly as on staging. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) Screenshots at 390 / 768 / 1440 px in light and dark, collapsed and expanded, were taken locally with the probe stubbed to an untrusted origin. They are not attached here (the CLI cannot upload images); a maintainer can add them, or the manual checks above cover the same states. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added a unified app-wide banner system with warning and critical styles, expandable details, optional actions, and dismissal controls. * Added clearer CSRF origin diagnostics, including the rejected origin, configuration guidance, trusted network ranges, and a copyable configuration value. * Banners now prioritize the highest-severity active message and remember dismissals appropriately. * **Bug Fixes** * Improved handling of unavailable CSRF status checks and browser storage, preventing unnecessary banners and preserving in-session dismissal. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:09:38 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#8011
No description provided.