Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

Fix flaky nightlies (#8478)

James Bruntond49649e6b33c
diff --git a/frontend/editor/src/core/components/viewer/nonpdf/MarkdownRenderer.tsx b/frontend/editor/src/core/components/viewer/nonpdf/MarkdownRenderer.tsx
index 42fec10d3c..1d0da2bf3a 100644
--- a/frontend/editor/src/core/components/viewer/nonpdf/MarkdownRenderer.tsx
+++ b/frontend/editor/src/core/components/viewer/nonpdf/MarkdownRenderer.tsx
@@ -1,12 +1,38 @@
-import React, { Component, Suspense, lazy, useState } from "react";
+import React, {
+ Component,
+ Suspense,
+ lazy,
+ useState,
+ type ComponentType,
+} from "react";
import { useTranslation } from "react-i18next";
import { Button } from "@app/ui/Button";
+type MarkdownRendererImplComponent = ComponentType<{ content: string }>;
+
+// Set once the chunk has loaded, so a block mounted after that renders markdown in
+// its first commit instead of committing the raw text and swapping it out.
+let loadedMarkdownRendererImpl: MarkdownRendererImplComponent | undefined;
+
// react-markdown + remark-gfm + micromark are ~120 KB gz and only needed when a
// markdown document is open (viewer) or a chat message arrives, so the heavy
// module is its own chunk while callers keep the synchronous signature.
const loadMarkdownRendererImpl = () =>
- import("@app/components/viewer/nonpdf/MarkdownRendererImpl");
+ import("@app/components/viewer/nonpdf/MarkdownRendererImpl").then(
+ (module) => {
+ loadedMarkdownRendererImpl = module.default;
+ return module;
+ },
+ );
+
+/**
+ * Starts loading the renderer, so markdown rendered later appears without the
+ * raw-text stand-in.
+ * */
+export function preloadMarkdownRenderer(): void {
+ if (loadedMarkdownRendererImpl) return;
+ loadMarkdownRendererImpl().catch(() => undefined);
+}
function rawMarkdown(content: string): React.ReactNode {
return <div style={{ whiteSpace: "pre-wrap" }}>{content}</div>;
@@ -39,9 +65,10 @@ function MarkdownBlock({ content }: { content: string }) {
// first render loses its state, so a lazy built inside it would be recreated
// on every retry and suspend forever. React also caches a lazy's rejected
// import, so the retry below swaps in a fresh one.
- const [MarkdownRendererImpl, setMarkdownRendererImpl] = useState(() =>
- lazy(loadMarkdownRendererImpl),
- );
+ const [MarkdownRendererImpl, setMarkdownRendererImpl] =
+ useState<MarkdownRendererImplComponent>(
+ () => loadedMarkdownRendererImpl ?? lazy(loadMarkdownRendererImpl),
+ );
const [attempt, setAttempt] = useState(0);
const [failed, setFailed] = useState(false);
diff --git a/frontend/editor/src/core/tests/helpers/api-stubs.ts b/frontend/editor/src/core/tests/helpers/api-stubs.ts
index 728165a43e..150bbbc99b 100644
--- a/frontend/editor/src/core/tests/helpers/api-stubs.ts
+++ b/frontend/editor/src/core/tests/helpers/api-stubs.ts
@@ -1,4 +1,4 @@
-import type { Page, Route } from "@playwright/test";
+import type { BrowserContext, Page, Route } from "@playwright/test";
/**
* Shared Playwright API stubs for Stirling-PDF E2E tests.
@@ -144,6 +144,23 @@ export interface MockAppApiOptions {
backendStatus?: "UP" | "DOWN";
}
+/**
+ * Answers every `/api/v1` request no other route claims with the empty 500 the
+ * dev proxy sends when no backend is listening. A request that reaches the proxy
+ * instead hits whatever backend runs locally, and in CI a large upload can hang
+ * there and crash the Chromium renderer.
+ *
+ * Register it before any other route on the context, so it is the last handler
+ * Playwright tries.
+ */
+export async function fulfillUnstubbedApis(
+ context: BrowserContext,
+): Promise<void> {
+ await context.route("**/api/v1/**", (route: Route) =>
+ route.fulfill({ status: 500, contentType: "text/plain", body: "" }),
+ );
+}
+
/**
* Register stub routes for the endpoints the app calls during bootstrap.
* Call this inside `test.beforeEach` before any `page.goto(...)`.
diff --git a/frontend/editor/src/core/tests/helpers/stub-test-base.ts b/frontend/editor/src/core/tests/helpers/stub-test-base.ts
index 1227c0d728..f881d1d343 100644
--- a/frontend/editor/src/core/tests/helpers/stub-test-base.ts
+++ b/frontend/editor/src/core/tests/helpers/stub-test-base.ts
@@ -1,6 +1,7 @@
import { test as base, expect } from "@playwright/test";
import {
bypassOnboarding,
+ fulfillUnstubbedApis,
mockAppApis,
seedCookieConsent,
type MockAppApiOptions,
@@ -14,7 +15,8 @@ import { suppressNativeFilePicker } from "@app/tests/helpers/ui-helpers";
* 1. Has the cookie-consent cookie seeded (banner never renders)
* 2. Has onboarding flags set in localStorage (modal never renders)
* 3. Has all bootstrap API endpoints stubbed via `mockAppApis()`
- * 4. Has already navigated to `/` by default (set `autoGoto: false` to skip)
+ * 4. Gets an empty 500 for any other `/api/v1` call, never the dev proxy
+ * 5. Has already navigated to `/` by default (set `autoGoto: false` to skip)
*
* Usage:
* import { test, expect } from "@app/tests/helpers/stub-test-base";
@@ -62,6 +64,13 @@ export const test = base.extend<StubFixtures>({
seedJwt: [false, { option: true }],
filesViewMode: [null, { option: true }],
+ // Set up with the context, before any hook adds its own context routes, so
+ // the fallback stays the last handler tried.
+ context: async ({ context }, use) => {
+ await fulfillUnstubbedApis(context);
+ await use(context);
+ },
+
page: async (
{ page, stubOptions, autoGoto, seedJwt, filesViewMode },
use,
diff --git a/frontend/editor/src/core/tests/stubbed/viewer-hot-reload-matrix.spec.ts b/frontend/editor/src/core/tests/stubbed/viewer-hot-reload-matrix.spec.ts
index 80eeae49d4..2d9484d0a4 100644
--- a/frontend/editor/src/core/tests/stubbed/viewer-hot-reload-matrix.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/viewer-hot-reload-matrix.spec.ts
@@ -495,7 +495,8 @@ test("a form apply keeps a fit-page zoom", async ({ page }) => {
.first();
await expect(field).toBeVisible({ timeout: 20_000 });
await field.fill("updated value");
- await page.keyboard.press("Tab");
+ // Tab can start an asynchronous scroll to the next field in WebKit.
+ await field.blur();
// Filling can scroll the field into view, so the baseline is read once the
// edit is done, right before the apply.
diff --git a/frontend/editor/src/proprietary/components/chat/ChatPanel.tsx b/frontend/editor/src/proprietary/components/chat/ChatPanel.tsx
index 391e53d187..94d662dcf2 100644
--- a/frontend/editor/src/proprietary/components/chat/ChatPanel.tsx
+++ b/frontend/editor/src/proprietary/components/chat/ChatPanel.tsx
@@ -10,7 +10,10 @@ import {
type RefCallback,
} from "react";
import { useMergedRef } from "@mantine/hooks";
-import { renderMarkdown } from "@app/components/viewer/nonpdf/MarkdownRenderer";
+import {
+ preloadMarkdownRenderer,
+ renderMarkdown,
+} from "@app/components/viewer/nonpdf/MarkdownRenderer";
import { TFunction } from "i18next";
import { useTranslation } from "react-i18next";
import {
@@ -441,6 +444,7 @@ export function ChatPanel({
// viewport left the scroll position.
useEffect(() => {
if (!expanded) return;
+ preloadMarkdownRenderer();
userScrolledUp.current = false;
requestAnimationFrame(() => {
const el = scrollRef.current;