fix(web): HTML visualizations show their full height instead of cropping and scrolling #22131
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 4 commits into
main fromrefs/pull/22131/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/htmlRender/HtmlRender.ts line 83OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -67,3 +67,17 @@6767 }6868 }696970+export class HtmlRenderViewportHeightError extends Schema.TaggedError<HtmlRenderViewportHeightError>()(71+ "HtmlRenderViewportHeightError",72+ { found: Schema.String },73+) {74+ override get message(): string {75+ return `The page uses a viewport height unit (${this.found}). The frame grows to fit the page, so a size that follows the viewport makes it grow again and again. Let content set the height, or use fixed pixel heights.`;76+ }77+}78+79+// The lookbehind skips base64 runs, such as an inlined image that happens to contain "1vh".80+const VIEWPORT_HEIGHT_UNIT = /(?<![\w.+/])\d*\.?\d+[sld]?vh(?![\w-])/i;81+82+const rejectViewportHeight = (html: string) => {83+ const found = VIEWPORT_HEIGHT_UNIT.exec(html)?.[0];apps/server/src/htmlRender/HtmlRender.ts lines 80 to 80OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -67,3 +67,14 @@6767 }6868 }696970+export class HtmlRenderViewportHeightError extends Schema.TaggedError<HtmlRenderViewportHeightError>()(71+ "HtmlRenderViewportHeightError",72+ { found: Schema.String },73+) {74+ override get message(): string {75+ return `The page uses a viewport height unit (${this.found}). The frame grows to fit the page, so a size that follows the viewport makes it grow again and again. Let content set the height, or use fixed pixel heights.`;76+ }77+}78+79+// The lookbehind skips base64 runs, such as an inlined image that happens to contain "1vh".80+const VIEWPORT_HEIGHT_UNIT = /(?<![\w.+/])\d*\.?\d+[sld]?vh(?![\w-])/i;
- apps/server/src/htmlRender/HtmlRender.ts line 80OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -67,3 +67,14 @@6767 }6868 }696970+export class HtmlRenderViewportHeightError extends Schema.TaggedError<HtmlRenderViewportHeightError>()(71+ "HtmlRenderViewportHeightError",72+ { found: Schema.String },73+) {74+ override get message(): string {75+ return `The page uses a viewport height unit (${this.found}). The frame grows to fit the page, so a size that follows the viewport makes it grow again and again. Let content set the height, or use fixed pixel heights.`;76+ }77+}78+79+// The lookbehind skips base64 runs, such as an inlined image that happens to contain "1vh".80+const VIEWPORT_HEIGHT_UNIT = /(?<![\w.+/])\d*\.?\d+[sld]?vh(?![\w-])/i;
- @@ -69,0 +72,21 @@72+ { found: Schema.String },73+) {74+ override get message(): string {75+ return `The page uses a viewport height unit (${this.found}). The frame grows to fit the page, so a size that follows the viewport makes it grow again and again. Let content set the height, or use fixed pixel heights.`;76+ }77+}78+79+// Only stylesheets and style attributes are checked, so page text that mentions80+// a unit passes; comments match first so their contents are skipped. Scripts81+// are still checked, since markup they insert applies. An unclosed comment,82+// tag, or quote runs to the end of the page, which keeps both patterns linear83+// on hostile input.84+const CSS_SOURCE =85+ /<!--[\s\S]*?(?:-->|$)|<style\b[^>]*(?:>|$)([\s\S]*?)(?:<\/style\s*>|$)|\sstyle\s*=\s*(?:"([^"]*)(?:"|$)|'([^']*)(?:'|$)|([^\s>]+))/gi;86+// The lookbehind skips base64 runs, such as an inlined image that happens to contain "1vh".87+const VIEWPORT_HEIGHT_UNIT = /(?<![\w.+/])(?:\d+(?:\.\d+)?|\.\d+)[sld]?vh(?![\w-])/i;88+89+const rejectViewportHeight = (html: string) => {90+ for (const [, sheet, doubleQuoted, singleQuoted, unquoted] of html.matchAll(CSS_SOURCE)) {91+ const css = sheet ?? doubleQuoted ?? singleQuoted ?? unquoted ?? "";92+ const found = VIEWPORT_HEIGHT_UNIT.exec(css)?.[0];@@ -69,0 +73,21 @@73+) {74+ override get message(): string {75+ return `The page uses a viewport height unit (${this.found}). The frame grows to fit the page, so a size that follows the viewport makes it grow again and again. Let content set the height, or use fixed pixel heights.`;76+ }77+}78+79+// Only stylesheets and style attributes are checked, so page text that mentions80+// a unit passes; comments match first so their contents are skipped. Scripts81+// are still checked, since markup they insert applies. An unclosed comment,82+// tag, or quote runs to the end of the page, which keeps both patterns linear83+// on hostile input.84+const CSS_SOURCE =85+ /<!--[\s\S]*?(?:-->|$)|<style\b[^>]*(?:>|$)([\s\S]*?)(?:<\/style\s*>|$)|\sstyle\s*=\s*(?:"([^"]*)(?:"|$)|'([^']*)(?:'|$)|([^\s>]+))/gi;86+// The lookbehind skips base64 runs, such as an inlined image that happens to contain "1vh".87+const VIEWPORT_HEIGHT_UNIT = /(?<![\w.+/])(?:\d+(?:\.\d+)?|\.\d+)[sld]?vh(?![\w-])/i;88+89+const rejectViewportHeight = (html: string) => {90+ for (const [, sheet, doubleQuoted, singleQuoted, unquoted] of html.matchAll(CSS_SOURCE)) {91+ const css = sheet ?? doubleQuoted ?? singleQuoted ?? unquoted ?? "";92+ const found = VIEWPORT_HEIGHT_UNIT.exec(css)?.[0];93+ if (found !== undefined) return Effect.fail(new HtmlRenderViewportHeightError({ found }));
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed