mirror of
https://github.com/hanzoai/site.git
synced 2026-11-20 21:14:28 +00:00
* Type scripts under strict Playwright's API the checks use is declared in host.ts (the package is the app repo's); caught errors read through why(). tabs-tree.test waits for the typed tabsTree. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type the shared components under strict Window globals (__lenis, __hzHold, google) and the two react-dom calls are declared in components/*.d.ts, since @types/react-dom is not a dependency and the lockfile is frozen. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type components/v2 under strict Props, state, refs and DOM events in the 93 v2 files. A2Motion's easing tuples are as const. Two real bugs: x-archimedes/MaskLines imported a NoJs that does not exist, and x-hypatia/PinChapters returned the element from a ref callback, which React 19 reads as a cleanup. AppSheet no longer sets aria-label to a JSX label. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type components/home under strict The race, cost and frontier figures, the plan cards, the repository card and the product stories take Run, Models and Plan types from lib. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type the hero devices and the app routes under strict HeroScene and its parts describe hero-scenes.json; the [slug] pages take params as a Promise, and metadata and viewport carry Next's types. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Give the integrations previews their Preview type Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Use the bench Card type for the closing cards Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk
24 lines
1.4 KiB
TypeScript
24 lines
1.4 KiB
TypeScript
/* <NoJs css="…" />: styles for visitors without JavaScript, with no <noscript>.
|
|
A <noscript> inside a client component cannot hydrate (React reads it as text in the browser), which puts Next's red
|
|
error badge on the page. This writes the same rules as a plain <style>, every selector scoped under html:not(.js);
|
|
app/layout.jsx sets html.js before first paint whenever JavaScript runs, so the rules apply only when it does not.
|
|
Server and client render the same string, so nothing mismatches. Works in server and client components.
|
|
Usage: <NoJs css=".my-step{opacity:1!important}" /> (plain CSS; @media blocks and keyframes are kept as they are). */
|
|
export function scopeNoJs(css: string) {
|
|
const src = String(css).replace(/<\/?style[^>]*>/g, '');
|
|
let out = '', i = 0;
|
|
while (i < src.length) {
|
|
const open = src.indexOf('{', i), close = src.indexOf('}', i);
|
|
if (open === -1) { out += src.slice(i); break; }
|
|
if (close !== -1 && close < open) { out += src.slice(i, close + 1); i = close + 1; continue; }
|
|
const head = src.slice(i, open), t = head.trim();
|
|
out += t.startsWith('@') || /^(from|to|\d+(\.\d+)?%)\b/.test(t) ? head + '{' : t.split(',').map((s) => 'html:not(.js) ' + s.trim()).join(',') + '{';
|
|
i = open + 1;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
export default function NoJs({ css }: { css: string }) {
|
|
return <style dangerouslySetInnerHTML={{ __html: scopeNoJs(css) }} />;
|
|
}
|