Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

perf: scope homepage scroll styling to header consumers

Amruth Pillai147421c9f55d
diff --git a/apps/web/src/features/homepage/landing.css b/apps/web/src/features/homepage/landing.css
index 260027dfc..f04fa7f40 100644
--- a/apps/web/src/features/homepage/landing.css
+++ b/apps/web/src/features/homepage/landing.css
@@ -160,7 +160,7 @@
--graphite: oklch(0.38 0.01 95 / 0.3);
/* Horizontal motion that points somewhere (slides, flights) is multiplied by this so it mirrors in RTL. */
--dir: 1;
- /* How dark Share's sky is while it's on screen; the engine writes it. */
+ /* Default ink before the scroll engine updates the individual consumers. */
--nt: 0;
}
diff --git a/apps/web/src/features/homepage/scroll.test.tsx b/apps/web/src/features/homepage/scroll.test.tsx
index 10c709715..6b51053af 100644
--- a/apps/web/src/features/homepage/scroll.test.tsx
+++ b/apps/web/src/features/homepage/scroll.test.tsx
@@ -36,6 +36,49 @@ describe("scroll engine", () => {
useLanding.setState({ designExiting: false });
});
+ it("keeps header progress and ink local while Share keeps its own night", async () => {
+ let shareTop = -450;
+ const motion = { matches: false, addEventListener: vi.fn(), removeEventListener: vi.fn() };
+ vi.stubGlobal("innerHeight", 900);
+ vi.stubGlobal("matchMedia", () => motion);
+ vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(function (this: HTMLElement) {
+ const top = this.dataset.scene === String(SCENE.share) ? shareTop : 0;
+ return { top, bottom: top + 1800, height: 1800, width: 0 } as DOMRect;
+ });
+ function Scenes() {
+ const root = useRef<HTMLDivElement>(null);
+ useScrollScenes(root);
+ return (
+ <div ref={root} data-testid="landing">
+ <header className="night-ink" />
+ <button type="button" className="night-ink">
+ Lamp
+ </button>
+ <section data-scene={SCENE.share} data-pin />
+ </div>
+ );
+ }
+ const { getByRole, getByTestId } = render(<Scenes />);
+ const root = getByTestId("landing");
+ const header = getByRole("banner");
+ const lamp = getByRole("button", { name: "Lamp" });
+ const share = root.querySelector<HTMLElement>("section");
+ if (!share) throw new Error("The scene harness did not render.");
+ await waitFor(() => expect(header.style.getPropertyValue("--sp")).toBe("0.500"));
+ expect(header.style.getPropertyValue("--nt")).toBe("1.000");
+ expect(lamp.style.getPropertyValue("--nt")).toBe("1.000");
+ expect(share.style.getPropertyValue("--nt")).toBe("1.000");
+ expect(root.style.getPropertyValue("--sp")).toBe("");
+ expect(root.style.getPropertyValue("--nt")).toBe("");
+
+ shareTop = -1350;
+ motion.matches = true;
+ fireEvent.scroll(window);
+ await waitFor(() => expect(header.style.getPropertyValue("--nt")).toBe("0.000"));
+ expect(lamp.style.getPropertyValue("--nt")).toBe("0.000");
+ expect(Number(share.style.getPropertyValue("--nt"))).toBeGreaterThan(0.9);
+ });
+
it("writes exit progress on pinned scenes and reports when Design hands its heading off", async () => {
const rects = new Map<string, { top: number; bottom: number; height: number }>([
[String(SCENE.design), { top: 0, bottom: 315, height: 900 }],
diff --git a/apps/web/src/features/homepage/scroll.ts b/apps/web/src/features/homepage/scroll.ts
index 67d553589..e40df132c 100644
--- a/apps/web/src/features/homepage/scroll.ts
+++ b/apps/web/src/features/homepage/scroll.ts
@@ -81,7 +81,7 @@ const DESIGN_EXIT_AT = 0.66;
/**
* How dark Share's sky is, from 0 to 1: night falls over the scene's first fifth and lifts into dawn over its last
- * stretch, both eased, so neither end snaps. The engine writes it as --nt on Share and on the page, for the header.
+ * stretch, both eased, so neither end snaps. The engine writes it as --nt on Share and the header's ink consumers.
*/
function shareNight(progress: number) {
return smoothstep(clamp01((progress - 0.02) / 0.22)) * (1 - smoothstep(clamp01((progress - 0.72) / 0.28)));
@@ -226,6 +226,8 @@ export function useScrollScenes(root: RefObject<HTMLElement | null>) {
const reducedMotion = window.matchMedia(reducedMotionQuery);
const sections = [...container.querySelectorAll<HTMLElement>("[data-scene]")];
+ const header = container.querySelector<HTMLElement>("header");
+ const nightInk = [...container.querySelectorAll<HTMLElement>(".night-ink")];
const sectionAt = (index: number) => sections.find((section) => section.dataset.scene === String(index));
// Rewriting an unchanged --p would still restyle the whole section, so only changes are written.
const writtenProgress = new WeakMap<HTMLElement, string>();
@@ -336,10 +338,10 @@ export function useScrollScenes(root: RefObject<HTMLElement | null>) {
}
const at = (scene: number) => progress[scene] ?? 0;
- // The active scene's progress, on the page, for the header nav's line under the current scene.
+ // Keep continuous header values local: inheriting them from the page restyles every scene.
const sceneProgress = clamp01(at(activeScene)).toFixed(3);
if (sceneProgress !== writtenSceneProgress) {
- container.style.setProperty("--sp", sceneProgress);
+ header?.style.setProperty("--sp", sceneProgress);
writtenSceneProgress = sceneProgress;
}
const scan = clamp01((at(SCENE.check) - 0.06) / 0.8);
@@ -347,12 +349,12 @@ export function useScrollScenes(root: RefObject<HTMLElement | null>) {
// Prepare's clock hands turn with the scroll; the minutes are written once, here, for the CSS and the readout.
const minutes = prepareMinutes(prepare);
- // Share's night: on the scene for its sky, and on the page while Share is on screen, for the header's ink.
+ // Share keeps its sky; the header and theme cord follow it only while Share is on screen.
const night = reduced ? 1 : shareNight(at(SCENE.share));
const pageNight = (activeScene === SCENE.share ? night : 0).toFixed(3);
if (`${night.toFixed(3)}|${pageNight}` !== writtenNight) {
sectionAt(SCENE.share)?.style.setProperty("--nt", night.toFixed(3));
- container.style.setProperty("--nt", pageNight);
+ for (const element of nightInk) element.style.setProperty("--nt", pageNight);
writtenNight = `${night.toFixed(3)}|${pageNight}`;
}