Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

docs(ok): correct what cascade layering buys the picker clip (PRD-7166) (#3889)

Andrew Mikofalvy034421cbf85d
diff --git a/packages/app/src/globals.css b/packages/app/src/globals.css
index 8fa1eb22e..389d84d5e 100644
--- a/packages/app/src/globals.css
+++ b/packages/app/src/globals.css
@@ -5769,15 +5769,38 @@ html.electron-mode [data-slot="sidebar-inner"] {
form an implicit final layer that outranks every named one — so this rule
sitting outside a layer beat every `max-w-*` a descendant carries no matter
how weak the selector was, which made it a FLOOR. Tailwind emits its
- utilities into `@layer utilities`, and `components` sorts before that, so
- from in here a descendant that states its own cap wins and one that states
- nothing is still capped. That is the ceiling the sibling producer promises
- when `deriveEditorSizeOptions` folds an `authorMaxWidth` into `min()`.
+ utilities into `@layer utilities`, and `components` sorts before that, so a
+ descendant stating its own cap as a UTILITY wins and one stating nothing is
+ still capped. The scoping is real: `.tag` a few blocks down is unlayered and
+ renders inside the slash-command Tag preview, so it outranks this rule by
+ the same law — invisibly today, since it also says `100%`.
+
+ That is a ceiling, but it is NOT the `min()` the sibling producer composes.
+ `deriveEditorSizeOptions` writes `min(authorMaxWidth, regionWidth)`, where
+ the narrower wins in both directions. A cascade override REPLACES this
+ declaration outright, wider included: a root carrying `max-w-96` beside a
+ fixed `width` inside a 284px wrapper resolves to 384px, which constrains
+ nothing and paints straight past the pane — the exact failure the first
+ paragraph describes. A picker that wants its own ceiling AND the clip has
+ to compose it, `max-w-[min(28rem,100%)]`, one character from the classes
+ this rule replaced.
+
+ The token the height axis uses (`--suggestion-menu-max-width`, consumed as
+ an inline `min(...)` at each root) is the one option that composes natively
+ and outranks every layer, which is why the producer chose it there. Kept a
+ rule here because it needs no per-component consumption; recorded so the
+ next reader does not re-derive the trade.
+
+ Unlike the reduced-transparency and composer-prosemirror blocks, which stay
+ unlayered so they always win, this one must be OVERRIDABLE — hence the
+ layer. Both policies are right for their surface.
Layering costs the fix nothing: `max-width` constrains `width` at the
used-value step whichever declaration won the cascade, so a `w-80` root in a
- 284px wrapper shrinks either way. `cascade-position.test.ts` is what holds
- the layer, because no layout-free tier can observe it. */
+ 284px wrapper shrinks either way. `globals.suggestion-clip-cascade.test.ts`
+ holds the layer, because no LAYOUT-FREE tier can observe it; a Playwright
+ probe injecting a capped descendant would pin it harder and is the rung not
+ bought yet. */
@layer components {
[data-suggestion-popup][data-suggestion-clipped] * {
max-width: 100%;
diff --git a/packages/app/src/editor/extensions/suggestion-clip-cascade-position.test.ts b/packages/app/src/globals.suggestion-clip-cascade.test.ts
similarity index 50%
rename from packages/app/src/editor/extensions/suggestion-clip-cascade-position.test.ts
rename to packages/app/src/globals.suggestion-clip-cascade.test.ts
index e99fb5178..df903abf5 100644
--- a/packages/app/src/editor/extensions/suggestion-clip-cascade-position.test.ts
+++ b/packages/app/src/globals.suggestion-clip-cascade.test.ts
@@ -3,22 +3,24 @@
*
* The rule makes a pane-clipped popup's content yield to the `max-width` the
* positioning pass writes on the wrapper. Whether it is a CEILING (a cap for
- * descendants that state nothing, overridable by one that states its own) or a
- * FLOOR (unconditionally overriding every author cap) is decided entirely by
- * its LAYER: the cascade sorts layer before specificity, unlayered author
- * declarations form an implicit final layer above every named one, and
+ * descendants that state nothing, overridable by a utility that states its
+ * own) or a FLOOR (unconditionally overriding every author cap) is decided
+ * entirely by its LAYER: the cascade sorts layer before specificity, unlayered
+ * author declarations form an implicit final layer above every named one, and
* Tailwind emits its utilities into `@layer utilities`. Unlayered, the rule
* beats every `max-w-*` no matter how weak its selector — which is what it did
- * for two commits, while a comment claimed the opposite.
+ * for two commits while a comment claimed the opposite.
*
- * Source text, deliberately. No runtime tier can reach this: jsdom has no
- * layout (`tests/dom/jsdom-preload.ts`), and the Playwright geometry specs
- * cannot discriminate a ceiling from a floor because no picker today carries a
- * descendant cap narrower than `100%` — the discriminating case is the future
- * one the rule exists to serve. CLAUDE.md's "never assert raw source text" is
- * scoped to React component tests and carves out exactly this: a property
- * whose runtime coverage is impossible. `comment-hue-contrast.test.ts` and
- * `build/chrome-tokens-vite-plugin.test.ts` read this same stylesheet the same
+ * Source text, for the reason `globals.cv-paint-lock.test.ts` gives for the
+ * same shape: jsdom has no layout (`tests/dom/jsdom-preload.ts`), so no
+ * LAYOUT-FREE tier can observe cascade position. A Playwright probe could —
+ * `page.addStyleTag` an `@layer utilities` cap onto a picker descendant and
+ * read the computed value — and after the wider-cap boundary the stylesheet
+ * comment now documents, that is the discriminating case worth buying. It is
+ * not bought yet; this file pins the declaration that the geometry specs in
+ * `selection-surface-pane-clip.e2e.ts` depend on. CLAUDE.md's "never assert
+ * raw source text" is scoped to React component tests and carves out exactly
+ * this, and `comment-hue-contrast.test.ts` reads the same stylesheet the same
* way.
*/
@@ -27,7 +29,7 @@ import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, test } from 'vitest';
-const GLOBALS_CSS = resolve(dirname(fileURLToPath(import.meta.url)), '../../globals.css');
+const GLOBALS_CSS = resolve(dirname(fileURLToPath(import.meta.url)), 'globals.css');
/** The shrink-propagation rule's selector, as written. */
const SHRINK_SELECTOR = '[data-suggestion-popup][data-suggestion-clipped] *';
@@ -41,10 +43,25 @@ const SHRINK_SELECTOR = '[data-suggestion-popup][data-suggestion-clipped] *';
*/
const LAYERS_BEFORE_UTILITIES = ['theme', 'base', 'components'];
-/** The `@layer <name> {` block containing `needle`, or null if unlayered. */
-function enclosingLayer(css: string, needle: string): string | null {
- const target = css.indexOf(needle);
- if (target === -1) throw new Error(`cascade-position: ${needle} not found in globals.css`);
+/**
+ * The `@layer <name> {` block containing the RULE whose prelude is `selector`,
+ * or null if it is unlayered.
+ *
+ * Comments are stripped first, then the selector is matched as a PRELUDE —
+ * followed by `{` — rather than as bare text. Both halves are load-bearing:
+ * this file's comments quote selectors constantly, and some of those quotes
+ * carry a brace, so a prelude match alone would still credit a comment inside
+ * an earlier `@layer base { … }` with an allow-listed layer name and pass
+ * while the real rule sat unlayered.
+ */
+function enclosingLayer(source: string, selector: string): string | null {
+ // Blank out comments rather than delete them, so every later index still
+ // lines up with the original text.
+ const css = source.replace(/\/\*[\s\S]*?\*\//g, (block) => ' '.repeat(block.length));
+ const prelude = new RegExp(`${selector.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*\\{`);
+ const found = prelude.exec(css);
+ if (!found) throw new Error(`cascade-position: no rule with prelude ${selector} in globals.css`);
+ const target = found.index;
const opener = /@layer\s+([a-zA-Z0-9_-]+)\s*\{/g;
let enclosing: string | null = null;
for (let match = opener.exec(css); match !== null; match = opener.exec(css)) {
@@ -95,4 +112,18 @@ describe('suggestion picker shrink rule cascade position', () => {
const css = '@layer base {\n .a { color: red }\n}\n.target { x: 1 }';
expect(enclosingLayer(css, '.target')).toBeNull();
});
+
+ test('the helper ignores the selector quoted in a comment', () => {
+ // The silent-pass path: a comment naming the selector inside an earlier
+ // allow-listed layer would report that layer for an unlayered rule.
+ const css = '@layer base {\n /* .target is capped elsewhere */\n}\n.target { x: 1 }';
+ expect(enclosingLayer(css, '.target')).toBeNull();
+ });
+
+ test('the helper ignores a quoted selector that carries its own brace', () => {
+ // A prelude match alone does not defeat this one — the quote looks exactly
+ // like a rule — and this stylesheet does contain comments of that shape.
+ const css = '@layer base {\n /* .target { x: 1 } is set below */\n}\n.target { x: 1 }';
+ expect(enclosingLayer(css, '.target')).toBeNull();
+ });
});