Skip to content

Commit 8cad217

Browse files
fix(shader-transitions,producer): harden CSS-only transition lifecycle and unblock CI
Three follow-on fixes after the optional-shader change rebased onto current main (PR #832 introduced page-side compositing and the producer's hf#732 layered pipeline since this PR was opened). shader-transitions/hyper-shader.ts - Treat `cache.prog === null` as the canonical immutable marker for CSS-only transitions via a new `isCssOnlyTransition()` helper. - `disposeCachedTransition()` now restores the always-ready CSS fallback state for prog=null caches instead of zeroing `fallback`/`ready` — the previous behaviour, combined with `markScenesDirty()` re-running the prewarm/capture pipeline, could put a CSS-only cache through the WebGL path and reach `renderShader(state.prog!)` with a null prog (Copilot review on lines 1168 + 1319). - `markScenesDirty()` skips CSS-only caches; they have no shader to recompile and no texture pyramid to recapture. - `ensureTransitionCachesReady()` filters CSS-only caches out of the prewarm work list. - `tickShader()` now routes on `cache.fallback || cache.prog === null` and threads a narrowed non-null `prog` local into `renderShader()`, removing the unsound `state.prog!` non-null assertion. - `initEngineMode()` filters CSS-only transitions before passing them to `installPageSideCompositor()`, which expects `shader: ShaderName` (required). Page-side compositing is shader-only; CSS crossfades stay on the GSAP opacity timeline. producer/render/stages/captureHdrHybridLoop.ts producer/render/stages/captureHdrSequentialLoop.ts - Guard `activeTransition.shader` against undefined: when omitted, route the Node-side blend through `crossfade` (the engine's canonical opacity blend, equivalent to `applyFallbackTransition()` on the page). - The hybrid path also bypasses the worker pool when `shaderName` is absent and runs `crossfade` inline. This addresses the Copilot review comments and unblocks the 5 failing CI jobs (Build, Typecheck, CLI smoke, Windows tests, Windows render) which all rooted in 4 TS errors at these exact sites. Co-authored-by: Cursor <[email protected]>
1 parent a78e49c commit 8cad217

3 files changed

Lines changed: 58 additions & 10 deletions

File tree

‎packages/producer/src/services/render/stages/captureHdrHybridLoop.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,17 @@ export async function runHybridLayeredFrameLoop(input: HybridLoopInput): Promise
260260
// awaits it. The encoder reorder buffer fences ordering so out-
261261
// of-order blend completion is fine.
262262
const frameIdx = i;
263+
// When the @hyperframes/shader-transitions composition omits the
264+
// shader on a transition entry, it requests a CSS crossfade. The
265+
// engine-side path uses applyFallbackTransition() on the page; the
266+
// producer's Node-side layered pipeline runs the equivalent here
267+
// by routing the blend through `crossfade`.
268+
const shaderName = activeTransition.shader;
263269
const dispatch: Promise<void> = (async () => {
264-
if (poolRef) {
270+
if (poolRef && shaderName) {
265271
const blendStart = Date.now();
266272
const result = await poolRef.run({
267-
shader: activeTransition.shader,
273+
shader: shaderName,
268274
bufferA: buffers.bufferA,
269275
bufferB: buffers.bufferB,
270276
output: buffers.output,
@@ -277,7 +283,9 @@ export async function runHybridLayeredFrameLoop(input: HybridLoopInput): Promise
277283
buffers.output = result.output;
278284
addHdrTiming(hdrPerf, "transitionCompositeMs", blendStart);
279285
} else {
280-
const transitionFn: TransitionFn = TRANSITIONS[activeTransition.shader] ?? crossfade;
286+
const transitionFn: TransitionFn = shaderName
287+
? (TRANSITIONS[shaderName] ?? crossfade)
288+
: crossfade;
281289
const blendStart = Date.now();
282290
transitionFn(
283291
buffers.bufferA,

‎packages/producer/src/services/render/stages/captureHdrSequentialLoop.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,13 @@ export async function runSequentialLayeredFrameLoop(input: SequentialLoopInput):
172172
});
173173
}
174174

175-
const transitionFn: TransitionFn = TRANSITIONS[activeTransition.shader] ?? crossfade;
175+
// CSS-crossfade transitions (shader omitted in the composition) take
176+
// the same Node-side blend path — `crossfade` is the engine's
177+
// canonical opacity blend, equivalent to applyFallbackTransition().
178+
const shaderName = activeTransition.shader;
179+
const transitionFn: TransitionFn = shaderName
180+
? (TRANSITIONS[shaderName] ?? crossfade)
181+
: crossfade;
176182
transitionFn(
177183
transitionBuffers.bufferA,
178184
transitionBuffers.bufferB,

‎packages/shader-transitions/src/hyper-shader.ts‎

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,11 @@ export function init(config: HyperShaderConfig): GsapTimeline {
11331133
canvasEl.style.display = "none";
11341134
return;
11351135
}
1136-
if (cache.fallback) {
1136+
// CSS-only transitions (prog === null) MUST take the fallback path. The
1137+
// fallback flag is the normal signal, but we also guard on prog to keep
1138+
// the invariant even if some path momentarily resets fallback while prog
1139+
// stays null (it can't be re-created — there is no shader to compile).
1140+
if (cache.fallback || cache.prog === null) {
11371141
state.active = true;
11381142
state.transitionIndex = activeIndex;
11391143
state.prog = null;
@@ -1147,9 +1151,12 @@ export function init(config: HyperShaderConfig): GsapTimeline {
11471151
return;
11481152
}
11491153

1154+
// Narrow cache.prog into a non-null local. The branch above already
1155+
// returned for prog === null, but TS can't track that across the function.
1156+
const prog = cache.prog;
11501157
state.active = true;
11511158
state.transitionIndex = activeIndex;
1152-
state.prog = cache.prog;
1159+
state.prog = prog;
11531160
state.progress = clampNumber((currentTime - cache.time) / cache.duration, 0, 1);
11541161
markTextureAccess(cache);
11551162

@@ -1166,7 +1173,7 @@ export function init(config: HyperShaderConfig): GsapTimeline {
11661173
renderShader(
11671174
gl,
11681175
quadBuf,
1169-
state.prog!, // non-null: fallback path returns before reaching here
1176+
prog,
11701177
interpolatedFromTex,
11711178
interpolatedToTex,
11721179
state.progress,
@@ -1456,15 +1463,28 @@ export function init(config: HyperShaderConfig): GsapTimeline {
14561463
cache.textureReady = false;
14571464
};
14581465

1466+
// Caches with prog === null are CSS crossfade transitions and must stay in
1467+
// the always-ready fallback state. Without this guard, disposeCachedTransition
1468+
// + markScenesDirty would route them through the WebGL prewarm path and
1469+
// tickShader would eventually call renderShader(state.prog!) with a null prog.
1470+
const isCssOnlyTransition = (cache: CachedTransition): boolean => cache.prog === null;
1471+
14591472
const disposeCachedTransition = (cache: CachedTransition): void => {
14601473
disposeTransitionTextures(cache);
14611474
cache.texturePromise = null;
14621475
cache.frames = [];
1476+
cache.lastError = undefined;
1477+
if (isCssOnlyTransition(cache)) {
1478+
cache.ready = true;
1479+
cache.fallback = true;
1480+
cache.persisted = true;
1481+
cache.textureReady = false;
1482+
return;
1483+
}
14631484
cache.ready = false;
14641485
cache.fallback = false;
14651486
cache.persisted = false;
14661487
cache.textureReady = false;
1467-
cache.lastError = undefined;
14681488
};
14691489

14701490
const markTextureAccess = (cache: CachedTransition): void => {
@@ -1571,6 +1591,9 @@ export function init(config: HyperShaderConfig): GsapTimeline {
15711591
let changed = false;
15721592
for (const cache of cachedTransitions) {
15731593
if (!sceneIds.has(cache.fromId) && !sceneIds.has(cache.toId)) continue;
1594+
// Skip CSS-only transitions: there is no shader to recompile and no
1595+
// texture pyramid to recapture, so they stay permanently ready.
1596+
if (isCssOnlyTransition(cache)) continue;
15741597
disposeCachedTransition(cache);
15751598
cache.dirty = true;
15761599
cache.cacheKey = "";
@@ -1893,7 +1916,11 @@ export function init(config: HyperShaderConfig): GsapTimeline {
18931916
if (transitionCachePromise) return transitionCachePromise;
18941917

18951918
transitionCachePromise = (async () => {
1896-
const work = cachedTransitions.filter((cache) => cache.dirty || !cache.ready);
1919+
// CSS-only transitions (prog === null) never need prewarming — they
1920+
// are always ready and route through applyFallbackTransition().
1921+
const work = cachedTransitions.filter(
1922+
(cache) => !isCssOnlyTransition(cache) && (cache.dirty || !cache.ready),
1923+
);
18971924
const workItems = work.map((cache) => ({
18981925
cache,
18991926
sampleCount: sampleCountForCache(cache),
@@ -2247,9 +2274,16 @@ function initEngineMode(
22472274
const rawH = Number(root?.getAttribute("data-height"));
22482275
const compWidth = Number.isFinite(rawW) && rawW > 0 ? rawW : 1920;
22492276
const compHeight = Number.isFinite(rawH) && rawH > 0 ? rawH : 1080;
2277+
// Page-side compositing only handles WebGL shader transitions. CSS
2278+
// crossfades are driven by GSAP opacity timelines elsewhere, so filter
2279+
// them out — passing them in would break the compositor's required
2280+
// `shader` field and produce a dead transition window with no rendering.
2281+
const shaderTransitions = transitions.filter(
2282+
(t): t is TransitionConfig & { shader: ShaderName } => !!t.shader,
2283+
);
22502284
installPageSideCompositor({
22512285
scenes,
2252-
transitions,
2286+
transitions: shaderTransitions,
22532287
bgColor,
22542288
accentColors,
22552289
width: compWidth,

0 commit comments

Comments
 (0)