fix(studio): use JSON.stringify for caption text escaping#794
Conversation
Only seek when the current playback time is outside the selected clip's range. When the user clicks a layer whose clip already contains the current time, the seek is skipped — avoiding unwanted preview jumps during playback. Fixes heygen-com#792
Replace manual backslash/single-quote escaping with JSON.stringify() in caption JS generation. The manual approach missed newlines, carriage returns, and other special characters that can break the generated JavaScript syntax. JSON.stringify handles all special characters and produces a double-quoted string literal that is always valid JS. Fixes heygen-com#625
vanceingalls
left a comment
There was a problem hiding this comment.
First review at 7a68285c.
Blocker — LayersPanel.tsx added as a NEW FILE bundled with the caption fix
The PR title and body describe a one-line caption fix in packages/studio/src/captions/generator.ts. The diff includes that fix (✓ — seg.text.replace(...) → JSON.stringify(seg.text), exactly what #625 also does), but it ALSO adds:
{"file":"packages/studio/src/components/editor/LayersPanel.tsx","status":"added","additions":295}
status: "added" for a file that already exists on main means this branch was forked before LayersPanel landed. On rebase against current main, the merge will either conflict (file exists in both) or silently overwrite the existing panel — losing every change committed to LayersPanel since the branch point. Either outcome breaks Studio.
This is the same defect that's also in #793 and #795 (all three Jefsky PRs from the same branch base).
Blocker — caption fix is duplicated by #625
#625 (hobostay) addresses the same caption-escaping bug with the same fix (JSON.stringify replacement), is already APPROVED by @jrusso1020, and has CI fully green. Either #794 or #625 should land — not both.
Strength — the caption fix itself is correct
packages/studio/src/captions/generator.ts:306-313: seg.text.replace(/\\/g, "\\\\").replace(/'/g, "\\'") only escapes backslash and single quotes — misses newlines, U+2028/U+2029 line separators, and any other JS-syntax-breaking char. JSON.stringify(seg.text) produces a valid double-quoted JS string for any input, including the embedded-newline case. The fix shape is the right call.
Recommendation
Two viable paths:
- Close #794, merge #625. Cleanest. #625 is already approved and CI-green.
- Drop the
LayersPanel.tsxnew-file from this PR, leaving onlygenerator.ts, then close #625 as superseded. Equivalent outcome, more work.
Either way, the bundled LayersPanel.tsx addition has to go before merge.
Verdict
Verdict: REQUEST CHANGES
Reasoning: PR title/body describe a one-line caption fix but the diff also adds LayersPanel.tsx as a new file (it already exists on main — merge will conflict or clobber). Caption fix itself is correct but duplicates the already-approved #625. Close this PR or strip the LayersPanel addition.
— Vai
Summary
Replace manual backslash/single-quote escaping with
JSON.stringify()in caption JS generation. The manual approach (seg.text.replace(...)) only handled backslash and single quotes, missing newlines, carriage returns, and other special characters that can break the generated JavaScript syntax.JSON.stringifyhandles all special characters and produces a double-quoted string literal that is always valid JS.What changed
packages/studio/src/captions/generator.ts—seg.textContentnow usesJSON.stringify(seg.text)instead of manual escaping.Closes #625