Skip to content

fix(admin): analytics pages load as their own document (route-only CSP); drop dead saas CSS - #279

Merged
AutomatosAI merged 1 commit into
mainfrom
fix/admin-analytics-csp-hard-nav
Sep 8, 2026
Merged

fix(admin): analytics pages load as their own document (route-only CSP); drop dead saas CSS#279
AutomatosAI merged 1 commit into
mainfrom
fix/admin-analytics-csp-hard-nav

Conversation

@AutomatosAI

@AutomatosAI AutomatosAI commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Why

/tenant-admin/analytics and /super-admin/analytics are the one place the admin CSP is wider ('unsafe-eval' for plotly.js). A CSP belongs to the document, not the route: a <Link> navigation into analytics keeps the policy of the page the user started on (plotly then can't run), and a <Link> out of analytics carries the wider policy onto pages that should not have it. Same class as the guide-video block fixed in #278.

What

  • lib/admin/hard-navigation.ts — the routes that need their own document, plus shouldFullLoad(pathname, href); unit-tested (tests/unit/hard-navigation.test.ts).
  • AdminSidebar and QuickActionsWidget render links into and out of those routes as plain <a> (full load); everything else stays on <Link>. No visual change.
  • Contract documented beside variantForServedPath in lib/security/csp.ts: add a route there → add it to the helper.
  • globals.css: .saas-shell / .saas-card / .saas-pill and their --saas-* tokens removed — last consumer (/settings) moved onto tenant tokens in fix(theme): complete the tenant token contract with a legibility floor #277; zero references remain.

Verify after deploy

Dashboard → click Analytics → charts render (full load). Analytics → click Orders → full load; document.querySelector('meta') not needed: check the response header content-security-policy on /tenant-admin/orders has no 'unsafe-eval'.

Summary by CodeRabbit

  • Bug Fixes

    • Improved navigation to and from admin analytics pages, ensuring pages load correctly with their specialized security settings.
    • Preserved seamless in-app navigation for other admin areas.
  • Style

    • Removed legacy storefront styling that was no longer used.
  • Documentation

    • Clarified security behavior for pages with expanded content requirements.

… saas CSS

The analytics pages carry a wider CSP ('unsafe-eval' for plotly.js) than
the rest of the admin. A policy belongs to the document, so a client-side
navigation into analytics kept the narrower policy of the page the user
started on, and a navigation out carried the wider one along — the same
trap that blocked the guide videos (#278), applied to scripts.

lib/admin/hard-navigation.ts names the routes that need their own document;
AdminSidebar and QuickActionsWidget render links into and out of them as
plain anchors. The contract is documented next to the CSP variant picker.

Also removes .saas-shell/.saas-card/.saas-pill and their tokens from
globals.css: their last consumer (/settings) moved onto tenant tokens in #277.
@AutomatosAI
AutomatosAI merged commit f16fc73 into main Sep 8, 2026
6 of 8 checks passed
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 9e626f0a-1547-46af-87a4-d9f91e9996cc

📥 Commits

Reviewing files that changed from the base of the PR and between 5adedab and 5518219.

📒 Files selected for processing (6)
  • nextjs_space/app/globals.css
  • nextjs_space/components/admin/AdminSidebar.tsx
  • nextjs_space/components/admin/QuickActionsWidget.tsx
  • nextjs_space/lib/admin/hard-navigation.ts
  • nextjs_space/lib/security/csp.ts
  • nextjs_space/tests/unit/hard-navigation.test.ts

📝 Walkthrough

Walkthrough

The change adds CSP-aware full-document navigation for admin analytics routes and removes legacy SaaS storefront styles from the global stylesheet.

Changes

Admin hard navigation

Layer / File(s) Summary
Navigation contract and validation
nextjs_space/lib/admin/hard-navigation.ts, nextjs_space/lib/security/csp.ts, nextjs_space/tests/unit/hard-navigation.test.ts
Analytics routes are identified by pathname. Navigation into and out of those routes requires a full document load. Unit tests cover route matching and navigation decisions.
Admin navigation wiring
nextjs_space/components/admin/AdminSidebar.tsx, nextjs_space/components/admin/QuickActionsWidget.tsx
The sidebar and quick actions render plain anchors for full-document destinations and Next.js links for other destinations. Shared link properties and content prevent duplicated markup.

Storefront CSS cleanup

Layer / File(s) Summary
Remove legacy storefront aliases
nextjs_space/app/globals.css
The stylesheet removes legacy SaaS variables and the .saas-shell, .saas-card, and .saas-pill classes. The related override comment is updated.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AdminComponent
  participant HardNavigation
  participant Browser
  AdminComponent->>HardNavigation: Check pathname and destination
  HardNavigation-->>AdminComponent: Return full-load decision
  AdminComponent->>Browser: Render anchor or Next.js Link
  Browser->>Browser: Load document with route CSP
Loading

Suggested reviewers: gerard161-site

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/admin-analytics-csp-hard-nav

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants