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
4 changes: 2 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? "";
Expand Down Expand Up @@ -128,7 +128,7 @@ export default function RootLayout({
return (
<html lang="en" className={`${fraunces.variable} ${sourceSans3.variable} ${notoSerifBengali.variable}`}>
<body className="min-h-screen flex flex-col bg-parchment text-ink font-sans selection:bg-amber-200 selection:text-amber-900 pb-[var(--niramay-content-inset)] transition-[padding-bottom] duration-300" suppressHydrationWarning>
<BrandSplash />
<BrandSplashMount />
<DisclaimerModal />
<CommandPalette />
<ThemeSync />
Expand Down
59 changes: 57 additions & 2 deletions components/brand/BrandSplash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -114,6 +155,8 @@ export const BrandSplash: React.FC<BrandSplashProps> = ({ 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);
}, []);
Expand Down Expand Up @@ -145,12 +188,24 @@ export const BrandSplash: React.FC<BrandSplashProps> = ({ autoDismissMs = 2800,
<div className="bs-gl bs-cc" /><span className="bs-gd" style={{left:"22%",top:"70%"}} /><span className="bs-gd" style={{left:"74%",top:"62%",animationDelay:".9s"}} /><span className="bs-gd" style={{left:"40%",top:"78%",animationDelay:"1.7s"}} /><span className="bs-gd" style={{left:"62%",top:"74%",animationDelay:"2.4s"}} /><span className="bs-gd" style={{left:"14%",top:"50%",animationDelay:"1.2s"}} /><span className="bs-gd" style={{left:"84%",top:"44%",animationDelay:"2.1s"}} />
<div className="bs-ctr">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img className="bs-mk" src="/brand/splash/mark.jpg" alt="" width={150} height={150} />
<img className="bs-mk" src={splashAssets().mark} alt="" width={150} height={150} />
{/* eslint-disable-next-line @next/next/no-img-element */}
<img className="bs-tx" src="/brand/splash/wordmark.jpg" alt="Niramay" width={195} height={48} />
<img className="bs-tx" src={splashAssets().wordmark} alt="Niramay" width={195} height={48} />
</div>

</div>
</>
);
};

/**
* 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<BrandSplashProps> = (props) => {
// Synchronous during the first client render, so the decision is made before
// BrandSplash is ever created.
if (isNativeShell()) return null;
return <BrandSplash {...props} />;
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
92 changes: 92 additions & 0 deletions scripts/test-brand-splash.ts
Original file line number Diff line number Diff line change
@@ -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("<img"));

stubWindow(globalThis, undefined);
const browserMarkup = renderToStaticMarkup(React.createElement(BrandSplashMount));
check("browser mount renders without throwing", typeof browserMarkup === "string");
check("browser mount does not emit native-only markup", !browserMarkup.includes("data-splash"));

// --- asset paths ------------------------------------------------------------
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 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 -----------------------
const fs = require("fs") as typeof import("fs");
const layout = fs.readFileSync("app/layout.tsx", "utf8");
check("layout imports BrandSplashMount", layout.includes("BrandSplashMount"));
check("layout no longer mounts the raw BrandSplash", !/<BrandSplash\s*\/>/.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);
}
Loading