fix(desktop): add legacy engine startup compatibility notice
This commit is contained in:
8 files changed
+869
-4
No files matched your search
+47
-1
@@ -1,7 +1,7 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { applyLegacyWebViewClass, isLegacyWebView, LEGACY_WEBVIEW_CLASS, missingLegacyWebViewCapabilities, supportsRegExpLookbehind } from "@/lib/ui/legacyWebView";
|
||||
import { applyLegacyWebViewClass, isBlockingCompatFailure, isLegacyWebView, LEGACY_WEBVIEW_CLASS, missingLegacyWebViewCapabilities, supportsRegExpLookbehind, webViewCompatReport } from "@/lib/ui/legacyWebView";
|
||||
|
||||
const supportedFeatures = new Set(["oklch", "color-mix-oklab", "color-mix-oklch", "has-selector", "dynamic-viewport", "min-function", "media-query-range"]);
|
||||
|
||||
@@ -85,6 +85,52 @@ describe("legacy WebView detection", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("inline engine probe report", () => {
|
||||
const setReport = (report: unknown) => {
|
||||
(window as unknown as Record<string, unknown>).__DBX_WEBVIEW_COMPAT__ = report;
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
delete (window as unknown as Record<string, unknown>).__DBX_WEBVIEW_COMPAT__;
|
||||
});
|
||||
|
||||
it("prefers the verdict the probe recorded before the bundle loaded", () => {
|
||||
setReport({ tier: "fatal", missing: ["layer"], engine: "Safari 15.2", platform: "macos", desktop: true, bypassed: false });
|
||||
|
||||
expect(webViewCompatReport()?.engine).toBe("Safari 15.2");
|
||||
expect(isLegacyWebView()).toBe(true);
|
||||
expect(missingLegacyWebViewCapabilities()).toEqual(["layer"]);
|
||||
});
|
||||
|
||||
it("treats a clean report as a supported engine", () => {
|
||||
setReport({ tier: "ok", missing: [], engine: "Safari 17.6", platform: "macos", desktop: true, bypassed: false });
|
||||
|
||||
expect(isLegacyWebView()).toBe(false);
|
||||
expect(missingLegacyWebViewCapabilities()).toEqual([]);
|
||||
});
|
||||
|
||||
it("ignores a malformed report and falls back to probing", () => {
|
||||
mockCssSupports(supportedFeatures);
|
||||
setReport({ tier: "ok" });
|
||||
|
||||
expect(webViewCompatReport()).toBeUndefined();
|
||||
expect(missingLegacyWebViewCapabilities()).toEqual([]);
|
||||
});
|
||||
|
||||
it("blocks startup only on a fatal engine the user did not choose to continue past", () => {
|
||||
expect(isBlockingCompatFailure()).toBe(false);
|
||||
|
||||
setReport({ tier: "degraded", missing: ["media-query-range"], engine: "", platform: "web", desktop: false, bypassed: false });
|
||||
expect(isBlockingCompatFailure()).toBe(false);
|
||||
|
||||
setReport({ tier: "fatal", missing: ["layer"], engine: "", platform: "macos", desktop: true, bypassed: false });
|
||||
expect(isBlockingCompatFailure()).toBe(true);
|
||||
|
||||
setReport({ tier: "fatal", missing: ["layer"], engine: "", platform: "macos", desktop: true, bypassed: true });
|
||||
expect(isBlockingCompatFailure()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("supportsRegExpLookbehind", () => {
|
||||
it("reports support when the engine compiles lookbehind patterns", () => {
|
||||
expect(supportsRegExpLookbehind()).toBe(true);
|
||||
|
||||
@@ -1,5 +1,28 @@
|
||||
export const LEGACY_WEBVIEW_CLASS = "dbx-legacy-webview";
|
||||
|
||||
/**
|
||||
* Verdict recorded by the inline probe in index.html, which runs before this bundle loads.
|
||||
* Reading it keeps a single source of truth, so the "upgrade your engine" notice and the
|
||||
* `dbx-legacy-webview` fallback layer can never disagree. Unlike the probes below, the inline
|
||||
* one also covers `@layer`, which is what decides whether the shell can be styled at all.
|
||||
*/
|
||||
export type WebViewCompatTier = "ok" | "degraded" | "fatal";
|
||||
|
||||
export interface WebViewCompatReport {
|
||||
tier: WebViewCompatTier;
|
||||
missing: string[];
|
||||
engine: string;
|
||||
platform: string;
|
||||
desktop: boolean;
|
||||
bypassed: boolean;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
__DBX_WEBVIEW_COMPAT__?: WebViewCompatReport;
|
||||
}
|
||||
}
|
||||
|
||||
type CssSupportCheck = {
|
||||
name: string;
|
||||
property?: string;
|
||||
@@ -39,10 +62,30 @@ function supports(check: CssSupportCheck): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
export function webViewCompatReport(): WebViewCompatReport | undefined {
|
||||
if (typeof window === "undefined") return undefined;
|
||||
const report = window.__DBX_WEBVIEW_COMPAT__;
|
||||
if (!report || typeof report.tier !== "string" || !Array.isArray(report.missing)) return undefined;
|
||||
return report;
|
||||
}
|
||||
|
||||
export function missingLegacyWebViewCapabilities(): string[] {
|
||||
const report = webViewCompatReport();
|
||||
if (report) return [...report.missing];
|
||||
|
||||
return MODERN_CSS_FEATURES.filter((feature) => !supports(feature)).map((feature) => feature.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the startup notice is blocking the app: the engine drops the whole layered
|
||||
* stylesheet, so mounting the shell would replace a readable message with an unstyled UI.
|
||||
* A user who chose "continue anyway" is not blocked again until the next session.
|
||||
*/
|
||||
export function isBlockingCompatFailure(): boolean {
|
||||
const report = webViewCompatReport();
|
||||
return report?.tier === "fatal" && report.bypassed !== true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Old WebKit (Safari < 16.4) throws SyntaxError when compiling regular
|
||||
* expressions with lookbehind or the named-group shapes Shiki's JavaScript
|
||||
|
||||
Reference in new issue
Block a user