From 75716fff0972f760bdfcb2bd4ed0d4bd8519ca55 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 09:27:05 +0000 Subject: [PATCH 1/2] fix(fields): draw a markdown heading in a grid cell at the cell's text size Claude-Session: https://claude.ai/code/session_01QsR2jUc3qp6bHKSWijbjds Co-authored-by: Claude --- .../markdownCellHeading-36344.test.tsx | 88 +++++++++++++++++++ ui/packages/fields/src/index.tsx | 9 +- .../fields/src/widgets/MarkdownContent.tsx | 49 ++++++++++- .../fields/src/widgets/richTextDisplay.tsx | 10 ++- 4 files changed, 149 insertions(+), 7 deletions(-) create mode 100644 ui/packages/fields/src/__tests__/markdownCellHeading-36344.test.tsx diff --git a/ui/packages/fields/src/__tests__/markdownCellHeading-36344.test.tsx b/ui/packages/fields/src/__tests__/markdownCellHeading-36344.test.tsx new file mode 100644 index 00000000000..3988bae48a7 --- /dev/null +++ b/ui/packages/fields/src/__tests__/markdownCellHeading-36344.test.tsx @@ -0,0 +1,88 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * objectstack#36344 — a markdown value that starts with a heading, drawn in a + * grid column, keeps the row the height of every other row. + * + * The grid clamps a rich-content cell to one line, but the line was the + * heading's: `prose-sm` draws an `h1` at heading size, so the cell showed a + * truncated H1 and the row grew. In a grid column (`inGridColumn`) the cell + * now draws its value in the `cell` face: no heading element, the heading as + * a bold line, and the body at the cell's own font size and line height. + * Every other caller keeps the `document` face and its heading elements. + * + * jsdom does no layout, so these pins read the element and class contract the + * row height rests on; the pixel readings are in the pull request. + */ + +import { describe, it, expect, afterEach } from 'vitest'; +import React from 'react'; +import { render, waitFor, cleanup } from '@testing-library/react'; +import '@testing-library/jest-dom'; +// Module scope, with the SAME specifier `MarkdownCellRenderer`'s `React.lazy` +// factory uses, so the lazy chunk is resolved before any assertion runs. +import '../widgets/MarkdownContent.js'; +import { getCellRenderer, resolveCellRendererType } from '../index'; + +const HEADING_VALUE = '# Heading\n\nBody with **bold** text'; +const HEADINGS = 'h1, h2, h3, h4, h5, h6'; + +afterEach(() => cleanup()); + +/** Resolve the way every read surface does, then settle past the Suspense fallback. */ +async function renderMarkdown(value: string, props: { inGridColumn?: boolean } = {}) { + const Renderer = getCellRenderer(resolveCellRendererType({ type: 'markdown' }) || 'markdown'); + const utils = render(); + const face = await waitFor(() => { + const el = utils.container.querySelector('[data-markdown-face]'); + if (!el) throw new Error('markdown body not rendered yet'); + return el; + }); + return { ...utils, face }; +} + +describe('objectstack#36344 — a markdown heading in a grid cell is drawn at the cell size', () => { + it('in a grid column: no heading element, the heading is a bold line, the body inherits the cell size', async () => { + const { face } = await renderMarkdown(HEADING_VALUE, { inGridColumn: true }); + + expect(face).toHaveAttribute('data-markdown-face', 'cell'); + expect(face.querySelector(HEADINGS)).toBeNull(); + + const heading = face.querySelector('[data-markdown-heading]'); + expect(heading?.tagName).toBe('P'); + expect(heading).toHaveTextContent('Heading'); + expect(heading).toHaveClass('font-semibold'); + + // The body takes the cell's own font size and line height, so the line + // the grid's one-line clamp shows is a line of the cell's text. + expect(face).toHaveClass('text-[length:inherit]', 'leading-[inherit]'); + + // The rest of the value is still formatted, not flattened to source text. + expect(face.querySelector('strong')).toHaveTextContent('bold'); + expect(face.textContent).not.toContain('#'); + }); + + it('in a grid column: every heading level is drawn the same way', async () => { + const value = ['# one', '## two', '### three', '#### four', '##### five', '###### six'].join('\n\n'); + const { face } = await renderMarkdown(value, { inGridColumn: true }); + expect(face.querySelector(HEADINGS)).toBeNull(); + expect(face.querySelectorAll('[data-markdown-heading]')).toHaveLength(6); + }); + + it('CONTROL — outside a grid column (the record page) the heading element and its size stay', async () => { + const { face } = await renderMarkdown(HEADING_VALUE); + + expect(face).toHaveAttribute('data-markdown-face', 'document'); + expect(face.querySelector('h1')).toHaveTextContent('Heading'); + expect(face.querySelector('[data-markdown-heading]')).toBeNull(); + expect(face).toHaveClass('prose', 'prose-sm'); + expect(face).not.toHaveClass('text-[length:inherit]'); + expect(face).not.toHaveClass('leading-[inherit]'); + }); +}); diff --git a/ui/packages/fields/src/index.tsx b/ui/packages/fields/src/index.tsx index 78786e3c620..89bf0000868 100644 --- a/ui/packages/fields/src/index.tsx +++ b/ui/packages/fields/src/index.tsx @@ -440,7 +440,14 @@ export interface CellRendererProps { alwaysShowYear?: boolean; /** * The cell is one of a grid COLUMN's cells, read against the cells above - * and below it (objectstack#25884). Read by the `date` cell only. + * and below it (objectstack#25884). Read by the `date` cell and the + * `markdown` cell. + * + * The `markdown` cell then draws its value in the cell face + * (objectstack#36344): a heading is a bold line at the cell's own text size + * instead of a heading element, so a value that starts with `# Heading` + * keeps the row's height. The record page does not pass it and keeps the + * heading sizes. * * A `date` field that declares no `format` then paints `formatDate`'s * absolute default face instead of `'relative'`, and the relative phrase diff --git a/ui/packages/fields/src/widgets/MarkdownContent.tsx b/ui/packages/fields/src/widgets/MarkdownContent.tsx index b07eaf2f67a..1933875016b 100644 --- a/ui/packages/fields/src/widgets/MarkdownContent.tsx +++ b/ui/packages/fields/src/widgets/MarkdownContent.tsx @@ -1,19 +1,60 @@ import React from 'react'; -import ReactMarkdown from 'react-markdown'; +import ReactMarkdown, { type Components } from 'react-markdown'; import remarkGfm from 'remark-gfm'; import rehypeSanitize from 'rehype-sanitize'; import { RICH_TEXT_SANITIZE_SCHEMA } from './sanitizedHtml.js'; +/** + * The two faces a markdown value is drawn in. + * + * - `document` — a full-size display (the record page, a readonly form field): + * headings keep their heading elements and the typography scale's sizes. + * - `cell` — one cell of a grid column, whose row is one line of the cell's own + * text (objectstack#36344). A heading is drawn as a bold line at the cell's + * text size, not as a heading element, and the body inherits the cell's font + * size and line height, so a value that starts with `# Heading` keeps the row + * the height of every other row. + */ +export type MarkdownFace = 'document' | 'cell'; + +const DOCUMENT_CLASS = 'prose prose-sm max-w-none dark:prose-invert break-words'; + +/** The cell face: the same typography, at the size and line height of the cell around it. */ +export const MARKDOWN_CELL_FACE_CLASS = `${DOCUMENT_CLASS} text-[length:inherit] leading-[inherit]`; + +function CellHeading({ children }: { children?: React.ReactNode }) { + return

{children}

; +} + +/** + * In the cell face no heading element is drawn: a heading inside a table cell + * is drawn at heading size by the typography scale, and it would also add one + * entry per row to the page's heading outline. + */ +const CELL_COMPONENTS: Components = { + h1: CellHeading, + h2: CellHeading, + h3: CellHeading, + h4: CellHeading, + h5: CellHeading, + h6: CellHeading, +}; + /** * Heavy markdown renderer, split into its own module so it can be lazy-loaded * by the cell/detail renderers (react-markdown pulls in ~100-200 KB). GitHub * Flavored Markdown + sanitization (defense against XSS in stored content), * against the same schema the `html` / `richtext` pipeline uses. */ -export default function MarkdownContent({ value }: { value: string }) { +export default function MarkdownContent({ value, face = 'document' }: { value: string; face?: MarkdownFace }) { + const cell = face === 'cell'; return ( -
- +
+ {value}
diff --git a/ui/packages/fields/src/widgets/richTextDisplay.tsx b/ui/packages/fields/src/widgets/richTextDisplay.tsx index 4fe7b400bc0..c327713eb33 100644 --- a/ui/packages/fields/src/widgets/richTextDisplay.tsx +++ b/ui/packages/fields/src/widgets/richTextDisplay.tsx @@ -90,13 +90,19 @@ function richTextSource(value: unknown): string | undefined { * What the cell holds is decided by {@link richTextSource} (objectui#8580): * `[]` is the No-value affordance, never a childless container, and an * object is the text the string class prints for it, never `[object Object]`. + * + * In a grid column (`inGridColumn`) the value is drawn in the `cell` face + * (objectstack#36344): a heading is a bold line at the cell's own text size, + * so a value that starts with `# Heading` does not grow its row. Every other + * caller — the record page, a readonly form field — keeps the `document` + * face and its heading sizes. */ -export function MarkdownCellRenderer({ value }: CellRendererProps): React.ReactElement { +export function MarkdownCellRenderer({ value, inGridColumn }: CellRendererProps): React.ReactElement { const text = richTextSource(value); if (text === undefined) return ; return ( {text.slice(0, 80)}}> - + ); } From 919a2f4f28912bce9b0732be53e76b81f7bc1dce Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 09:36:44 +0000 Subject: [PATCH 2/2] test(plugin-grid): pin the markdown cell face inside the one-line clamp; add changeset Claude-Session: https://claude.ai/code/session_01QsR2jUc3qp6bHKSWijbjds Co-authored-by: Claude --- .changeset/36344-markdown-cell-heading.md | 10 ++++++ .../ObjectGrid.richTextOneLine-12480.test.tsx | 33 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 .changeset/36344-markdown-cell-heading.md diff --git a/.changeset/36344-markdown-cell-heading.md b/.changeset/36344-markdown-cell-heading.md new file mode 100644 index 00000000000..00fcdf2a8d8 --- /dev/null +++ b/.changeset/36344-markdown-cell-heading.md @@ -0,0 +1,10 @@ +--- +'@object-ui/fields': patch +--- + +fix(fields): a markdown value that starts with a heading no longer draws at heading size in a list cell + +Clause-②: no +Metadata-protocol: none + +In a grid column (list views and related lists pass `inGridColumn`), the `markdown` cell now draws its value in a cell face: a heading is a bold line at the cell's own text size instead of a heading element, and the body takes the cell's font size and line height. A value such as `# Heading` showed a truncated H1 and grew its row; the row now keeps the height of every other row. The record page and readonly form fields keep the full document face and its heading sizes. Nothing changes in what an author writes, and no export changes. diff --git a/ui/packages/plugin-grid/src/__tests__/ObjectGrid.richTextOneLine-12480.test.tsx b/ui/packages/plugin-grid/src/__tests__/ObjectGrid.richTextOneLine-12480.test.tsx index 3b4fe6ba241..f150e728a11 100644 --- a/ui/packages/plugin-grid/src/__tests__/ObjectGrid.richTextOneLine-12480.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/ObjectGrid.richTextOneLine-12480.test.tsx @@ -157,3 +157,36 @@ describe('objectui#12480 — a rich-content cell keeps the one-line row', () => expect(screen.getByText('Account 8').closest('td')?.querySelector('.truncate')).not.toBeNull(); }); }); + +/** + * objectstack#36344 — the one line the clamp shows is a line of the cell's + * text. A markdown value that starts with `# Heading` filled the clamp's one + * line with an H1, so the row grew to the heading's line height. The grid + * passes `inGridColumn` to every column cell, and the markdown cell then draws + * its value in the `cell` face: no heading element, the cell's own font size + * and line height. jsdom does no layout; the pixel readings are in the PR. + */ +describe('objectstack#36344 — a markdown heading in a grid cell does not draw at heading size', () => { + it('a markdown cell whose value starts with a heading draws no heading element inside the clamp', async () => { + desktop(); + const rows = [ + { id: 'r1', name: 'Account 1', description: '# Heading\n\nBody' }, + { id: 'r2', name: 'Account 2' }, + ]; + renderGrid(rows, [ + { field: 'name', label: 'Name' }, + { field: 'description', label: 'Description' }, + ]); + await waitFor(() => expect(screen.getByText('Account 2')).toBeInTheDocument()); + const row1 = bodyRows()[0] as HTMLElement; + const face = await waitFor(() => { + const el = row1.querySelector('[data-testid="grid-rich-text-one-line"] [data-markdown-face]'); + if (!el) throw new Error('markdown cell not rendered yet'); + return el; + }); + expect(face).toHaveAttribute('data-markdown-face', 'cell'); + expect(face).toHaveClass('text-[length:inherit]', 'leading-[inherit]'); + expect(face.querySelector('[data-markdown-heading]')).toHaveTextContent('Heading'); + expect(document.querySelector('tbody h1, tbody h2, tbody h3, tbody h4, tbody h5, tbody h6')).toBeNull(); + }); +});