remotion: Truncate long blob URLs in delayRender labels - #9813
Conversation
There was a problem hiding this comment.
Reviewed changes — adds blob URL truncation and a non-string runtime guard to truncateSrcForLabel, used in delayRender labels for <Img> and <CanvasImage>.
- Handle blob: URLs — extends the existing
data:URL truncation to also coverblob:URLs, keeping delayRender labels compact. - Non-string type guard — adds a
typeofcheck so the function doesn't throw at runtime if a non-string value reaches it.
ℹ️ Tests should cover the new behavior
The test file at packages/core/src/test/truncate-src-for-label.test.ts doesn't cover blob URL truncation or the non-string type guard. Worth adding — the existing tests on data URLs are a good template to follow.
Technical details
# Missing test coverage for blob URLs and non-string guard
## Affected sites
- `packages/core/src/test/truncate-src-for-label.test.ts` — no test for blob URL truncation or non-string guard.
## Required outcome
- Add a test: a long `blob:` URL should be truncated (mirroring the existing data URL test on line 21-28).
- Add a test: passing `null` or `undefined` returns a safe fallback string rather than throwing.
## Open questions for the human
- What's the right expected return value for non-string input? The current implementation returns `String(src ?? '')` which produces `""` for `null`/`undefined` but `"[object Object]"` for objects. Decide the desired contract before writing tests.DeepSeek Pro (free via Pullfrog for OSS) (Claude Opus not used — the program covers this model; add its provider key to run your pick) | 𝕏
| // unreadable and bloats log output | ||
| export function truncateSrcForLabel(src: string): string { | ||
| if (src.startsWith('data:') && src.length > 100) { | ||
| if (typeof src !== 'string') { |
There was a problem hiding this comment.
The type signature (src: string) contradicts the runtime typeof guard. If non-string values can reach this function in practice, update the parameter type to unknown. Otherwise the guard is dead code at compile time and callers writing truncateSrcForLabel(foo as string) will never be caught by the type system.
Technical details
# Type guard contradicts declared parameter type
## Affected sites
- `packages/core/src/truncate-src-for-label.ts:3` — `src: string` vs `typeof src !== 'string'` guard at line 4
- `packages/core/src/Img.tsx:145,200,211` — callers use `as string` assertions
- `packages/core/src/canvas-image/CanvasImage.tsx:230,305,344,388` — `actualSrc` from `usePreload` flows in unasserted
## Required outcome
- If non-string values can reach this function at runtime: change the signature to `src: unknown` and remove the `as string` assertions at call sites.
- If they cannot: drop the `typeof` guard and fix any callers that pass potentially-non-string values at the source.| export function truncateSrcForLabel(src: string): string { | ||
| if (src.startsWith('data:') && src.length > 100) { | ||
| if (typeof src !== 'string') { | ||
| return String(src ?? ''); |
There was a problem hiding this comment.
The fallback String(src ?? '') silently converts any non-string to a string representation, which could mask real bugs. If a caller passes an object (e.g. a ref that hasn't mounted), the label becomes "[object Object]" — no more useful than a crash, and harder to notice. Consider returning a fixed descriptive label like "[unexpected source]" or widening the type and letting TypeScript catch the problem at compile time instead.
…e guards in truncateSrcForLabel
remotion: Truncate long blob URLs in delayRender labels

Description
This PR updates
truncateSrcForLabelinpackages/core/src/truncate-src-for-label.ts.Details
blob:URLs alongsidedata:URLs to keep delayRender labels compact.