From 4208b1e25c7aabde8226f2ad607ed2d76974de37 Mon Sep 17 00:00:00 2001 From: Void Date: Thu, 12 Nov 2026 09:53:04 +0000 Subject: [PATCH] Pin the bubble row's shrink-to-column declarations A test reads the emitted layout.css.ts and fails when BubbleColumn, BubbleContentRow or BubbleContent lose min-width 0 or the row loses max-width 100%, the cause of the 782px own-message quote. Co-Authored-By: Claude Sonnet 5.5 --- .../message/layout/bubbleBounds.test.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/app/components/message/layout/bubbleBounds.test.ts diff --git a/src/app/components/message/layout/bubbleBounds.test.ts b/src/app/components/message/layout/bubbleBounds.test.ts new file mode 100644 index 00000000..3d95a839 --- /dev/null +++ b/src/app/components/message/layout/bubbleBounds.test.ts @@ -0,0 +1,38 @@ +import { describe, expect, it } from 'vitest'; +import zlib from 'zlib'; +import { compile, processVanillaFile } from '@vanilla-extract/integration'; + +// A long reply quote (nowrap) sized the own-message row to 782px on a 390px phone. The row, the column and the bubble +// must be able to shrink to their parent, so pin the emitted declarations (as phoneTapTargets.test.ts does). +const emitted = async () => { + const filePath = `${process.cwd()}/src/app/components/message/layout/layout.css.ts`; + const { source } = await compile({ filePath, cwd: process.cwd(), identOption: 'debug' }); + const code = await processVanillaFile({ source, filePath, identOption: 'debug' }); + const bytes = Buffer.from( + (code.match(/source=#?([A-Za-z0-9+/=]+)/) as RegExpMatchArray)[1], + 'base64' + ); + return (bytes[0] === 0x1f && bytes[1] === 0x8b ? zlib.gunzipSync(bytes) : bytes).toString(); +}; + +const declarations = (css: string, className: string): string[] => { + const rule = new RegExp(`^\\.layout_${className}__[\\w-]+ \\{\\n([^}]*)\\}`, 'm').exec(css); + expect(rule, `no .layout_${className} rule emitted`).toBeTruthy(); + return (rule as RegExpExecArray)[1].split('\n').map((l) => l.trim().replace(/;$/, '')); +}; + +describe('bubble rows shrink to their column', () => { + it.each([ + ['BubbleColumn', ['min-width: 0']], + ['BubbleContentRow', ['min-width: 0', 'max-width: 100%']], + ['BubbleContent', ['min-width: 0']], + ])('%s', async (name, expected) => { + const css = await emitted(); + expect(declarations(css, name)).toEqual(expect.arrayContaining(expected)); + }); + + it('BubbleContent keeps its 800px cap inside the column width', async () => { + const css = await emitted(); + expect(declarations(css, 'BubbleContent').join('\n')).toMatch(/max-width: min\(100%, 50rem\)/); + }); +});