diff --git a/app/layout.tsx b/app/layout.tsx index 16a4cfa..a80f96b 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -39,7 +39,7 @@ import { FloatingInstallBanner } from "@/components/pwa/FloatingInstallBanner"; import { DisclaimerModal } from "@/components/DisclaimerModal"; import { CommandPalette } from "@/components/command/CommandPalette"; import { ThemeSync } from "@/components/layout/ThemeSync"; -import { BrandSplash } from '@/components/brand/BrandSplash'; +import { BrandSplashMount } from '@/components/brand/BrandSplash'; const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL ?? "https://pdfly-source.github.io"; const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH ?? ""; @@ -128,7 +128,7 @@ export default function RootLayout({ return ( - + diff --git a/components/brand/BrandSplash.tsx b/components/brand/BrandSplash.tsx index be091a1..f704d80 100644 --- a/components/brand/BrandSplash.tsx +++ b/components/brand/BrandSplash.tsx @@ -7,6 +7,47 @@ export interface BrandSplashProps { onComplete?: () => void; } +// Base path injected by CI when the site is served from GitHub Pages (empty in +// dev). Every static asset in the site is prefixed with it (see NiramayLogo); +// this component used to hard-code root-absolute paths, which 404 under +// /niramay and render as broken-image placeholders. +const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH ?? ""; + +/** Splash artwork URLs, resolved against the deployed base path. */ +export const splashAssets = (basePath: string = BASE_PATH) => ({ + mark: `${basePath}/brand/splash/mark.jpg`, + wordmark: `${basePath}/brand/splash/wordmark.jpg`, +}); + +type NativeBridgeWindow = { + AppMintlyNative?: { isNativeApp?: () => unknown } | null; +}; + +/** + * True when this page is running inside the AppMintly Android wrapper, which + * draws its own native launch splash (NiramaySplashView). That surface is the + * only splash the app is meant to show, so the web splash must not exist there + * at all. + * + * The bridge is injected with addJavascriptInterface() before the WebView + * loads any URL, so it is already present when this module is evaluated - the + * check therefore runs before the first React render and cannot flash. + */ +export const isNativeShell = (win?: NativeBridgeWindow | null): boolean => { + const target = win ?? (typeof window !== "undefined" ? (window as unknown as NativeBridgeWindow) : null); + try { + const bridge = target?.AppMintlyNative; + if (!bridge || typeof bridge.isNativeApp !== "function") return false; + return bridge.isNativeApp() === true; + } catch { + // A throwing or partial bridge must never break the web splash. + return false; + } +}; + +// Evaluated at module load, before any render of this component. +const NATIVE_SHELL_AT_LOAD = isNativeShell(); + const CSS = ` .bs-root{position:fixed;inset:0;z-index:9999;overflow:hidden;isolation:isolate;transition:opacity .4s ease} .bs-root.is-fading{opacity:0} @@ -114,6 +155,8 @@ export const BrandSplash: React.FC = ({ autoDismissMs = 2800, seen = true; } if (seen) return; + // Never in the Android wrapper: the native NiramaySplashView is the splash. + if (NATIVE_SHELL_AT_LOAD || isNativeShell()) return; const t = setTimeout(() => setVisible(true), 0); return () => clearTimeout(t); }, []); @@ -145,12 +188,24 @@ export const BrandSplash: React.FC = ({ autoDismissMs = 2800,
{/* eslint-disable-next-line @next/next/no-img-element */} - + {/* eslint-disable-next-line @next/next/no-img-element */} - Niramay + Niramay
); }; + +/** + * Mount point used by the root layout. Inside the Android wrapper this renders + * nothing at all - BrandSplash is never mounted, so no second splash, no + * broken-image fallback and no fade can occur ahead of the real app screen. + */ +export const BrandSplashMount: React.FC = (props) => { + // Synchronous during the first client render, so the decision is made before + // BrandSplash is ever created. + if (isNativeShell()) return null; + return ; +}; diff --git a/package.json b/package.json index 9c1ad9f..a208a06 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "lint": "eslint .", "clean": "next clean", "test:ai": "tsx scripts/test-ai-engine.ts", - "test:branding": "tsx scripts/verify-branding.ts" + "test:branding": "tsx scripts/verify-branding.ts", + "test:splash": "tsx scripts/test-brand-splash.ts" }, "dependencies": { "@hookform/resolvers": "^5.2.1", diff --git a/scripts/test-brand-splash.ts b/scripts/test-brand-splash.ts new file mode 100644 index 0000000..75c7aa4 --- /dev/null +++ b/scripts/test-brand-splash.ts @@ -0,0 +1,92 @@ +/** + * Regression test for the duplicate-splash defect in the Android app. + * + * The app's WebView page carried its own BrandSplash. With broken (404) asset + * paths it rendered as a blank cream screen with two broken-image icons right + * after the native NiramaySplashView retired, before DisclaimerModal appeared. + * Inside the AppMintly wrapper the web splash must not exist at all. + * + * These checks exercise the real component, not a copy of its logic. + */ +import React from "react"; +import { renderToStaticMarkup } from "react-dom/server"; +import { + BrandSplashMount, + isNativeShell, + splashAssets, +} from "../components/brand/BrandSplash"; + +let pass = 0; +const failures: string[] = []; + +const check = (name: string, cond: boolean) => { + if (cond) { + pass += 1; + console.log(`PASS ${name}`); + } else { + failures.push(name); + console.log(`FAIL ${name}`); + } +}; + +// --- native detection ------------------------------------------------------- +check("native bridge reporting true is detected", isNativeShell({ AppMintlyNative: { isNativeApp: () => true } })); +check("native bridge reporting false is not native", !isNativeShell({ AppMintlyNative: { isNativeApp: () => false } })); +check("missing bridge is not native", !isNativeShell({})); +check("null bridge is not native", !isNativeShell({ AppMintlyNative: null })); +check("bridge without isNativeApp is not native", !isNativeShell({ AppMintlyNative: {} as never })); +check("throwing bridge is not native (fails open to the web splash)", !isNativeShell({ AppMintlyNative: { isNativeApp: () => { throw new Error("bridge"); } } })); +check("trusted-looking truthy string is not accepted as native", !isNativeShell({ AppMintlyNative: { isNativeApp: () => "true" as unknown as boolean } })); +check("no window at all (SSR pass) is not native", !isNativeShell(undefined)); + +// --- rendering: the wrapper must produce no splash markup ------------------- +const stubWindow = (g: typeof globalThis, bridge: unknown) => { + (g as { window?: unknown }).window = { AppMintlyNative: bridge }; +}; + +stubWindow(globalThis, { isNativeApp: () => true }); +const nativeMarkup = renderToStaticMarkup(React.createElement(BrandSplashMount)); +check("native shell renders no splash markup at all", nativeMarkup === ""); +check("native shell emits no bs-root element", !nativeMarkup.includes("bs-root")); +check("native shell emits no splash images", !nativeMarkup.includes("/.test(layout)); +const component = fs.readFileSync("components/brand/BrandSplash.tsx", "utf8"); +check( + "component source no longer uses root-absolute splash src", + !/src="\/brand\/splash\//.test(component), +); +check( + "native guard sits before the splash is made visible", + component.indexOf("NATIVE_SHELL_AT_LOAD || isNativeShell()") < component.indexOf("setVisible(true)"), +); + +console.log(`\n${pass}/${pass + failures.length} brand-splash checks passed`); +if (failures.length) { + console.error(`FAILURES:\n- ${failures.join("\n- ")}`); + process.exit(1); +}