From 912da909bfb20c0b1c62ad43471b347b51b4d9f4 Mon Sep 17 00:00:00 2001 From: AppMintly Agent Date: Thu, 12 Nov 2026 11:36:49 +0000 Subject: [PATCH 1/2] fix(splash): never mount the web splash inside the Android app The app's WebView page ships its own BrandSplash and mounts it in the root layout. Inside the AppMintly wrapper that produced a second splash after the native NiramaySplashView retired: the component's images pointed at /brand/splash/*.jpg, which 404 under the /niramay base path, so it rendered as a blank cream screen with two broken-image icons before DisclaimerModal showed. BrandSplashMount consults the AppMintlyNative bridge synchronously during the first client render (the bridge is injected before any URL loads, so the check runs before BrandSplash is created) and returns null in the app. The web splash still ships unchanged for browser and PWA visitors, and its artwork now resolves against the deployed base path instead of the domain root. --- app/layout.tsx | 4 +- components/brand/BrandSplash.tsx | 59 +++++++++++++++++++++- scripts/test-brand-splash.ts | 86 ++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 scripts/test-brand-splash.ts 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/scripts/test-brand-splash.ts b/scripts/test-brand-splash.ts new file mode 100644 index 0000000..05319c4 --- /dev/null +++ b/scripts/test-brand-splash.ts @@ -0,0 +1,86 @@ +/** + * 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); +} From b388234007c6d66f14ce671c5e77cdf946fe5bb6 Mon Sep 17 00:00:00 2001 From: AppMintly Agent Date: Thu, 12 Nov 2026 11:39:08 +0000 Subject: [PATCH 2/2] test(splash): pin the native-only suppression and the base-path artwork scripts/test-brand-splash.ts renders the real mount point against a stub AppMintlyNative bridge (21 checks): suppressed in the app, unchanged in a browser, artwork URLs follow NEXT_PUBLIC_BASE_PATH, and a throwing or partial bridge fails open to the web splash instead of breaking the page. --- package.json | 3 ++- scripts/test-brand-splash.ts | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) 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 index 05319c4..75c7aa4 100644 --- a/scripts/test-brand-splash.ts +++ b/scripts/test-brand-splash.ts @@ -60,11 +60,17 @@ const deployed = splashAssets("/niramay"); check("mark resolves under the deployed base path", deployed.mark === "/niramay/brand/splash/mark.jpg"); check("wordmark resolves under the deployed base path", deployed.wordmark === "/niramay/brand/splash/wordmark.jpg"); check("dev base path has no doubled slash", !splashAssets("").mark.includes("//")); +// The default must follow the configured base path: "/brand/..." only when the +// site is served from the domain root (dev), "/niramay/brand/..." when deployed. +const configuredBase = process.env.NEXT_PUBLIC_BASE_PATH ?? ""; const defaults = splashAssets(); -check("default asset paths carry no root-absolute /brand/splash", !/^\/brand\/splash\//.test(defaults.mark) && !/^\/brand\/splash\//.test(defaults.wordmark)); +check( + "default asset paths follow the configured base path", + defaults.mark === `${configuredBase}/brand/splash/mark.jpg` && + defaults.wordmark === `${configuredBase}/brand/splash/wordmark.jpg`, +); // --- integration: the layout mounts the gated wrapper ----------------------- -// eslint-disable-next-line @typescript-eslint/no-var-requires const fs = require("fs") as typeof import("fs"); const layout = fs.readFileSync("app/layout.tsx", "utf8"); check("layout imports BrandSplashMount", layout.includes("BrandSplashMount"));