Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion rivet-cli/src/serve/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,16 @@ pub(crate) fn print_layout(content: &str, _state: &AppState) -> Html<String> {
<style>{FONTS_CSS}{CSS}</style>
<style>
@media print {{ nav, .context-bar, .nav-search-hint, #cmd-k-overlay, #loading-bar, .graph-controls, .svg-viewer-toolbar {{ display: none !important; }} main {{ padding: 1rem; max-width: 100%; }} .shell {{ display: block; }} }}
body {{ background: #fff; }}
body {{ background: #fff; color: #1a1a2e; }}
.shell {{ display: block; }}
nav, .context-bar, #cmd-k-overlay, #loading-bar {{ display: none; }}
main {{ padding: 1.5rem 2rem; max-width: 100%; }}
</style>
<script src="/assets/mermaid.js"></script>
<script>
mermaid.initialize({{startOnLoad:false,theme:'default',securityLevel:'loose'}});
document.addEventListener('DOMContentLoaded',function(){{mermaid.run({{querySelector:'.mermaid'}}).catch(function(){{}});}});
</script>
</head>
<body>
<main>
Expand Down
5 changes: 3 additions & 2 deletions rivet-cli/src/serve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,11 @@ async fn wrap_full_page(

let response = next.run(req).await;

// Only wrap GET requests to view routes (not /, assets, or APIs)
// Only wrap GET requests to view routes (not assets or APIs)
// For "/" without print=1, the index handler already renders the full page.
if method == axum::http::Method::GET
&& !is_htmx
&& path != "/"
&& (path != "/" || is_print)
&& !path.starts_with("/api/")
&& !path.starts_with("/assets/")
&& !path.starts_with("/wasm/")
Expand Down
25 changes: 25 additions & 0 deletions tests/playwright/print-and-errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ test.describe("Print Mode", () => {
await expect(page.locator("body")).toContainText("STPA");
});

test("print view includes mermaid.js script", async ({ page }) => {
await page.goto("/stats?print=1");
const mermaidScript = page.locator('script[src="/assets/mermaid.js"]');
await expect(mermaidScript).toBeAttached();
});

test("print view loads mermaid library", async ({ page }) => {
await page.goto("/stats?print=1");
await page.waitForLoadState("networkidle");
const hasMermaid = await page.evaluate(
() => typeof (window as any).mermaid !== "undefined",
);
expect(hasMermaid).toBe(true);
});

test("print view uses print layout (no sidebar)", async ({ page }) => {
// Use a non-root path so the print middleware activates
await page.goto("/stats?print=1");
// Print layout should show "printed view" footer
await expect(page.locator("body")).toContainText("printed view");
// And should NOT have the sidebar nav
const navCount = await page.locator("nav").count();
expect(navCount).toBe(0);
});

test("print button exists and has no URL constructor in onclick", async ({
page,
}) => {
Expand Down
Loading