test: scope no-js preview visibility gate

This commit is contained in:
2026-09-08 23:40:27 +03:00
parent 8aa147c25a
commit dfb923d38d
2 changed files with 14 additions and 4 deletions

View File

@@ -2,20 +2,27 @@ import { readFile } from "node:fs/promises";
import { resolve } from "node:path"; import { resolve } from "node:path";
const outputPath = resolve(".next/server/app/index.html"); const outputPath = resolve(".next/server/app/index.html");
const html = await readFile(outputPath, "utf8"); const source = await readFile(resolve("src/app/page.tsx"), "utf8");
// The placeholder is the first frame for a newly-created project. It must stay // The placeholder is the first frame for a newly-created project. It must stay
// visible when a client chunk is delayed or rejected; later product pages are // visible when a client chunk is delayed or rejected; later product pages are
// free to replace it and choose their own bounded animation policy. // free to replace it and choose their own bounded animation policy.
if (html.includes("Fluw template")) { if (source.includes("Fluw template")) {
const html = await readFile(outputPath, "utf8");
const main = html.match(/<main\b[\s\S]*?<\/main>/i)?.[0]; const main = html.match(/<main\b[\s\S]*?<\/main>/i)?.[0];
if (!main) { if (!main) {
throw new Error("Fluw placeholder is missing its main landmark"); throw new Error("Fluw placeholder is missing its main landmark");
} }
const criticalElement = main.match(
/<[^>]*\bdata-fluw-preview-critical="true"[^>]*>/i,
)?.[0];
if (!criticalElement) {
throw new Error("Fluw placeholder is missing its preview-critical element");
}
if ( if (
/style="[^"]*(?:opacity\s*:\s*0(?:[;"]|\s)|visibility\s*:\s*hidden|display\s*:\s*none)/i.test( /style="[^"]*(?:opacity\s*:\s*0(?:[;"]|\s)|visibility\s*:\s*hidden|display\s*:\s*none)/i.test(
main, criticalElement,
) )
) { ) {
throw new Error( throw new Error(

View File

@@ -14,7 +14,10 @@ export default function Home() {
<main className="min-h-screen overflow-hidden bg-background text-white"> <main className="min-h-screen overflow-hidden bg-background text-white">
<section className="relative mx-auto flex min-h-screen w-full max-w-[900px] items-center justify-center px-4 py-10 sm:px-6 lg:px-8"> <section className="relative mx-auto flex min-h-screen w-full max-w-[900px] items-center justify-center px-4 py-10 sm:px-6 lg:px-8">
<div className="w-full"> <div className="w-full">
<div className="mx-auto flex max-w-[760px] flex-col items-center text-center"> <div
className="mx-auto flex max-w-[760px] flex-col items-center text-center"
data-fluw-preview-critical="true"
>
<div className="mb-8 flex items-center gap-3 text-left"> <div className="mb-8 flex items-center gap-3 text-left">
<FluwSquareIcon /> <FluwSquareIcon />