Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/architecture/layer-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ verified_by:
[
packages/core/src/Layer/useLayer.test.tsx,
packages/core/src/Layer/layerViewportInset.test.ts,
packages/core/src/Layer/layerViewportInset.consumer-build.test.mjs,
packages/core/src/Layer/useLayerKeyboardClearance.test.tsx,
packages/core/src/Layer/LayerProvider.test.tsx,
packages/core/src/Layer/toastHost.test.tsx,
Expand Down Expand Up @@ -784,6 +785,14 @@ be updated only as that work ships.
`spec:AST-003` does not cover INV21 or INV22; `spec:AST-059` DEC-9 and DEC-10
govern them. It does not cover the INV7 gaps either.

INV11 gap: a StyleX build outside Core that resolves
`Layer/layerViewportInset.stylex`, as a swizzled layer component imports it, to
its built `dist` file gets an undefined variable: that file holds the
constants' values, and the build reads each constant as a variable that
nothing defines. A build that compiles the published source entry defines
them. No record decides the fix, and `spec:AST-003` does not cover it.
`layerViewportInset.consumer-build.test.mjs` shows the gap.

INV14 and INV15 are not met yet, and `spec:AST-003` does not cover them. The
runtime owns the shared exit copy (INV13, `placeLayerExitCopy`) and the shared
presentation hold (`Layer/presentationHold.ts`), which Popover uses for its
Expand Down Expand Up @@ -978,6 +987,7 @@ this current architecture record.
| INV19 | `layerPortalBoundary.test.ts`, `RichTextEditor.portalHost.test.tsx`, and `LayerBoundary.a11y.browser.spec.ts`, `TooltipDecorator.a11y.browser.spec.ts` and `DecoratorPortal.a11y.browser.spec.ts` in Chromium and WebKit | A corrected layer whose host is inside an editor-managed root, and that has no nearer layer root, rendered inside that root; a nested layer moved out of its parent layer's root; a layer that is safe inline moved; a moved wrapper whose `dir` differs from its host's |
| INV3–INV5 | `useLayer.test.tsx` and `anchorName.test.ts` | A mode leaks geometry, RTL resolves from the wrong context, fallback clips, or a sibling anchor is lost |
| INV11 | `layerViewportInset.test.ts`, `useLayer.test.tsx`, and the `Core/Layer` viewport-inset stories under the story play guard at a desktop and a phone viewport; `BaseTypeahead.incremental.test.tsx` and the Typeahead incremental-results stories for the `spec:AST-092` FR6 exception | A second gutter definition, a `100%`-of-span cap, a layer narrower than its explicit size, a layer box wider than the viewport, a layer inside the gutter, or a layer that slides toward an off-screen anchor; for an open Typeahead popup, a later list for the same query that flips it to the other side or grows it past the room on its side, or a first list for a query that is capped to the span beside the trigger |
| INV11 gap | `layerViewportInset.consumer-build.test.mjs`, which asserts the gap while it stands | A StyleX build outside Core that resolves `Layer/layerViewportInset.stylex` to its built file defines every variable it references, or the test cannot build the app: the test fails |
| INV12 | The `Core/Layer` viewport-inset stories' first-frame comparison, and `useLayer.test.tsx`'s synchronous anchor read; for the check after a scroll stops, `useLayer.test.tsx`'s `scrollend` and 150 ms fallback cases (one re-pick, in the first painted frame after the stop, with no read in the scroll handler), the `Core/Layer` story "anchor stays in view while the page scrolls" and the Tooltip suites' scroll-edge cases; a Chromium trace at 4× CPU of a wheel scroll that carries a Tooltip's trigger to the scroll edge counts the forced layouts per scroll before and after DEC-8: page scroll 27–42 → 5, a scrolling panel 7 → 5, the Slider value bubble 12–22 → 5 | A layer whose first painted rectangle differs from its settled one; a box check, a re-pick or a forced layout for a layer in a scroll frame or a scroll handler; a re-pick before the first painted frame after a scroll stops, or more than one per stop; a painted frame that shows a layer that keeps its anchor clear over its anchor |
| INV11, INV12 | The software keyboard's cap: `useLayerKeyboardClearance.test.tsx` for its rule, its timing, its read before first paint, and the inset's hold; the `PopoverKeyboard`, `keyboardCappedLists` and `SelectorKeyboardInset` browser specs for its rendered geometry | A layer that runs under the keyboard, or is capped though the keyboard does not reach it; a cap that changes more than once per keyboard movement or under a press; a layer opened with the keyboard up whose first frame is uncapped or paints its content past its box; a layer that reads the inset and moves down when the keyboard report ends |
| INV13 | `layerExitCopy.test.ts` and `layerExitCopy.interaction.browser.spec.ts` | A copy with an id, a form name, a form owner, or pointer reach; a copy off the layer's drawn box; a copy outside the top layer; a second copy for one layer |
Expand Down
139 changes: 139 additions & 0 deletions packages/core/src/Layer/layerViewportInset.consumer-build.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

/**
* @file layerViewportInset.consumer-build.test.mjs
* @input Uses Babel, the StyleX compiler, Core's build config, and the
* published `./Layer/layerViewportInset.stylex` entry as Core builds it
* @output Shows that a StyleX build outside Core that reads the built layer
* viewport inset references CSS variables Core's stylesheet does not
* define, while the gap stands
* @position Regression test for the published layer viewport inset entry
* (spec:AST-059 FR1, FR7)
*/

import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import {transformAsync} from '@babel/core';
import stylexBabelPlugin from '@stylexjs/babel-plugin';
import {afterAll, beforeAll, describe, expect, it} from 'vitest';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const SRC = path.resolve(__dirname, '..');
const CORE_ROOT = path.resolve(SRC, '..');

/** Core's sources whose compiled CSS defines what the entry may reference. */
const CORE_SOURCES = [
'Layer/layerViewportInset.stylex.ts',
'theme/tokens.stylex.ts',
];

/** @type {string} */
let app;

async function compileCore(relative) {
const filename = path.join(SRC, relative);
return transformAsync(await fs.readFile(filename, 'utf8'), {
babelrc: false,
configFile: path.join(CORE_ROOT, 'babel.config.json'),
filename,
});
}

beforeAll(async () => {
// An app with Core installed as it is published: the entry is the built
// file at the path the package's exports name.
app = await fs.realpath(
await fs.mkdtemp(path.join(os.tmpdir(), 'astryx-inset-consumer-')),
);
const core = path.join(app, 'node_modules/@astryxdesign/core');
await fs.mkdir(path.join(core, 'dist/Layer'), {recursive: true});
await fs.writeFile(
path.join(core, 'package.json'),
JSON.stringify({name: '@astryxdesign/core'}),
);
const built = await compileCore('Layer/layerViewportInset.stylex.ts');
await fs.writeFile(
path.join(core, 'dist/Layer/layerViewportInset.stylex.js'),
built?.code ?? '',
);
await fs.writeFile(
path.join(app, 'package.json'),
JSON.stringify({name: 'inset-consumer-app'}),
);
}, 60_000);

afterAll(async () => {
if (app) await fs.rm(app, {recursive: true, force: true});
});

/** The CSS an app's own StyleX build emits for `source`. */
async function compileApp(source) {
const filename = path.join(app, 'src/Sheet.js');
await fs.mkdir(path.dirname(filename), {recursive: true});
await fs.writeFile(filename, source);
const result = await transformAsync(source, {
babelrc: false,
configFile: false,
filename,
plugins: [
[
stylexBabelPlugin,
{
dev: false,
runtimeInjection: false,
unstable_moduleResolution: {type: 'commonJS', rootDir: app},
// The published entry resolves through node_modules.
aliases: {
'@astryxdesign/core/Layer/layerViewportInset.stylex': [
path.join(
app,
'node_modules/@astryxdesign/core/dist/Layer/layerViewportInset.stylex.js',
),
],
},
},
],
],
});
return stylexBabelPlugin.processStylexRules(
result?.metadata?.stylex ?? [],
false,
);
}

/** Every custom property Core's compiled stylesheet defines. */
async function coreDefinitions() {
const rules = [];
for (const relative of CORE_SOURCES) {
rules.push(...((await compileCore(relative))?.metadata?.stylex ?? []));
}
const css = stylexBabelPlugin.processStylexRules(rules, false);
return new Set([...css.matchAll(/(--[\w-]+)\s*:/g)].map(match => match[1]));
}

describe('the published layer viewport inset in an app StyleX build (spec:AST-059 FR7)', () => {
// The INV11 gap in architecture:layer-runtime. When the gap closes this
// test fails: then it asserts that no reference is undefined.
it('references the three constants it reads as variables Core leaves undefined', async () => {
const css = await compileApp(`
import * as stylex from '@stylexjs/stylex';
import {layerViewportInset} from '@astryxdesign/core/Layer/layerViewportInset.stylex';
export const styles = stylex.create({
sheet: {
maxBlockSize: layerViewportInset.maxBlockSize,
maxInlineSize: layerViewportInset.maxInlineSize,
marginBlockStart: layerViewportInset.gutterBlockStart,
},
});
`);
const defined = await coreDefinitions();
// A variable with no fallback that nothing defines makes the whole
// declaration invalid, so the app's sheet loses its cap.
const undefinedReferences = [...css.matchAll(/var\((--[\w-]+)\)/g)]
.map(match => match[1])
.filter(name => !defined.has(name));
expect(undefinedReferences).toHaveLength(3);
});
});
Loading