From b84835c413bb35be442d59b0fa41ff50a8819455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Tue, 3 Nov 2026 07:47:49 +0000 Subject: [PATCH] feat(studio-server): the preview records the kind and origin of each early error (#7041) * feat(studio-server): the preview records the kind and origin of each early error * fix(studio-server): write preview script values with U+2028/2029 and < escaped --- packages/core/src/studioPreviewMark.ts | 1 + .../studio-server/src/routes/preview.test.ts | 65 ++++++++++++++++++- packages/studio-server/src/routes/preview.ts | 21 ++++-- 3 files changed, 82 insertions(+), 5 deletions(-) diff --git a/packages/core/src/studioPreviewMark.ts b/packages/core/src/studioPreviewMark.ts index 81acab6575..f291aa83fa 100644 --- a/packages/core/src/studioPreviewMark.ts +++ b/packages/core/src/studioPreviewMark.ts @@ -16,6 +16,7 @@ export function defersMediaIn(doc: Document): boolean { export const STUDIO_PREVIEW_UPCOMING_ATTR = "data-hf-upcoming"; export const STUDIO_PREVIEW_LAZY_ATTR = "data-hf-preview-lazy"; export const STUDIO_PREVIEW_ERRORS = "__hfPreviewErrors"; +export const STUDIO_PREVIEW_ERROR_KINDS = "__hfPreviewErrorKinds"; export const refusedPreviewMessage = (status: number) => `The preview page could not be loaded (HTTP ${status}).`; diff --git a/packages/studio-server/src/routes/preview.test.ts b/packages/studio-server/src/routes/preview.test.ts index b52f5ce2fe..0faf30e605 100644 --- a/packages/studio-server/src/routes/preview.test.ts +++ b/packages/studio-server/src/routes/preview.test.ts @@ -22,12 +22,18 @@ import { tmpdir } from "node:os"; import { join, parse } from "node:path"; import { ensureHfIds } from "@hyperframes/parsers/hf-ids"; import { + STUDIO_PREVIEW_ERROR_KINDS, STUDIO_PREVIEW_ERRORS, STUDIO_PREVIEW_CAPTURE_MODE, STUDIO_PREVIEW_MARK_META, } from "@hyperframes/core/studio-preview-mark"; import { AFTER_FONTS_SCRIPT_TYPE } from "@hyperframes/core/compiler"; -import { PREVIEW_BUNDLE_OPTIONS, PREVIEW_CAPTURE_PARAM, registerPreviewRoutes } from "./preview"; +import { + PREVIEW_BUNDLE_OPTIONS, + PREVIEW_CAPTURE_PARAM, + registerPreviewRoutes, + scriptJson, +} from "./preview"; import { registerFileRoutes } from "./files"; import { createPreviewDocumentStore } from "../helpers/previewDocumentStore"; import { MAX_OPEN_MEDIA_RANGE_BYTES } from "../helpers/mediaRange"; @@ -374,6 +380,63 @@ describe("registerPreviewRoutes", () => { expect(previewWindow[STUDIO_PREVIEW_ERRORS]).toEqual(["Uncaught Error: GSAP could not load"]); }); + it("writes a value into a script so it cannot close the tag or end the line", () => { + const out = scriptJson("