Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): a swizzled Outline type-checks against the package's Markdown plugins (#10641)

Cindy Zhangf092308149a1
diff --git a/.changeset/core-markdown-plugin-types-swizzle.md b/.changeset/core-markdown-plugin-types-swizzle.md
new file mode 100644
index 0000000000..1dcaf770d6
--- /dev/null
+++ b/.changeset/core-markdown-plugin-types-swizzle.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] A swizzled `Outline` (or another copy that carries Core's Markdown plugin protocol) now type-checks against the package's Markdown plugins: `MarkdownPluginEntry` and `MarkdownTransform` carry their node type on a shared, versioned key instead of a module-local symbol, so the package's and the copy's types match. The member exists only in types; runtime trust and claim checks are unchanged. No API changes.
+
+@cixzhang
diff --git a/docs/specs/AST-110-swizzle-output/spec.md b/docs/specs/AST-110-swizzle-output/spec.md
index 65aeb87218..ca5913fbd3 100644
--- a/docs/specs/AST-110-swizzle-output/spec.md
+++ b/docs/specs/AST-110-swizzle-output/spec.md
@@ -218,17 +218,17 @@ and the repository proves it before a change that could break it merges.
## Verification
-| Contract | Verification | Representative states | Mutation or failure expectation |
-| -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| FR1 | Eject every offered component into a clean project; type-check and bundle | Every component in `swizzle --list`; Core, Lab, Charts, RichText, Vega; a component that imports an npm dependency | A type or resolve error, or an import of a path the owner's `exports` lacks or of `./internal/*`, other than a StyleX module another Astryx package exports there (FR1), fails, or a dependency the copy imports goes unreported |
-| FR2 | Import graph of each output | Helpers in `utils`, `hooks`, `Layer`; nested folders; colocated tests and docs; a helper an earlier swizzle wrote, identical and different | A copied file imports a module that is neither in the output nor a public export, or a test, story, spec, or doc is copied, or an existing helper other than an owner module (FR4) is overwritten |
-| FR3 | Render a copied and a package layer component together; inspect stores; open, stack, and Escape | Dialog over package Popover; BottomSheet over package Dialog; modality; a copied `useToast` under the package `LayerProvider`; a symbol-branded object passed between copy and package; a copied Dialog announcing beside a package component; a package picker inside a copied Dialog announcing a result count; a package grouped control inside a copied overlay | In either direction (copy under package, package under copy): two stores of one protocol version exist in a document, Escape and focus return differ from the package alone, a copied consumer misses the package provider, a brand check fails, a second live region appears instead of one announcer (`spec:AST-086` FR9), an announcement escapes the open modal (`spec:AST-086` FR14), or group context crosses the layer boundary (`spec:AST-038` FR7) |
-| FR3 | `sharedContexts.test.tsx` "gives each React its own context under a key, and one per React": a second React instance loads a copy of the shared-context module | Two copies on one React; a copy on a second React in the same process | Two copies on one React getting different contexts, or a copy on a second React getting the same context object, fails |
-| FR4 | Scan each output for private data-attribute names and selectors; compare copied owner modules with the package's | Components that reach an owner module | A hand-written private attribute name or selector, or an edited owner module, in the output |
-| FR5 | Render package and copy side by side under a theme with component overrides; compare | Default; each variant; a theme component override; a copy built by `@astryxdesign/build` | A theme override, documented class name, data attribute, or theme target reaches one and not the other |
-| FR5 | Swizzle into a new folder, an empty one, a marked one, and one holding a product module; read the folder and the `swizzle.copy` result | Default output; `--output` to a product folder; a folder of earlier copies with no marker | A marker lands in a folder that holds a product module, a new, empty or marked folder is left unmarked, or the result omits what a skipped folder holds |
-| FR6 | The component's own interaction and accessibility checks run against the copy | Keyboard, pointer, screen-reader tree | A check that passes on the package fails on the copy |
-| FR7 | The required test lane's swizzle proof and the release-time proof; both cover Core's list and every integration package's components through `--package` | A change to component source; a change to the swizzle copy; an unrelated change; Core, Lab, Charts, RichText, Vega | An offered component missing from the proof, a failure that does not block, a new required context, the proof adding wall-clock time to the slowest required check, or the proof pushing its job past the pull-request time budget |
+| Contract | Verification | Representative states | Mutation or failure expectation |
+| -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| FR1 | Eject every offered component into a clean project; type-check and bundle | Every component in `swizzle --list`; Core, Lab, Charts, RichText, Vega; a component that imports an npm dependency | A type or resolve error, or an import of a path the owner's `exports` lacks or of `./internal/*`, other than a StyleX module another Astryx package exports there (FR1), fails, or a dependency the copy imports goes unreported |
+| FR2 | Import graph of each output | Helpers in `utils`, `hooks`, `Layer`; nested folders; colocated tests and docs; a helper an earlier swizzle wrote, identical and different | A copied file imports a module that is neither in the output nor a public export, or a test, story, spec, or doc is copied, or an existing helper other than an owner module (FR4) is overwritten |
+| FR3 | Render a copied and a package layer component together; inspect stores; open, stack, and Escape | Dialog over package Popover; BottomSheet over package Dialog; modality; a copied `useToast` under the package `LayerProvider`; a symbol-branded object passed between copy and package; a swizzled Outline type-checked against the package's `MarkdownPluginEntry`; a copied Dialog announcing beside a package component; a package picker inside a copied Dialog announcing a result count; a package grouped control inside a copied overlay | In either direction (copy under package, package under copy): two stores of one protocol version exist in a document, Escape and focus return differ from the package alone, a copied consumer misses the package provider, a brand check fails, a second live region appears instead of one announcer (`spec:AST-086` FR9), an announcement escapes the open modal (`spec:AST-086` FR14), or group context crosses the layer boundary (`spec:AST-038` FR7) |
+| FR3 | `sharedContexts.test.tsx` "gives each React its own context under a key, and one per React": a second React instance loads a copy of the shared-context module | Two copies on one React; a copy on a second React in the same process | Two copies on one React getting different contexts, or a copy on a second React getting the same context object, fails |
+| FR4 | Scan each output for private data-attribute names and selectors; compare copied owner modules with the package's | Components that reach an owner module | A hand-written private attribute name or selector, or an edited owner module, in the output |
+| FR5 | Render package and copy side by side under a theme with component overrides; compare | Default; each variant; a theme component override; a copy built by `@astryxdesign/build` | A theme override, documented class name, data attribute, or theme target reaches one and not the other |
+| FR5 | Swizzle into a new folder, an empty one, a marked one, and one holding a product module; read the folder and the `swizzle.copy` result | Default output; `--output` to a product folder; a folder of earlier copies with no marker | A marker lands in a folder that holds a product module, a new, empty or marked folder is left unmarked, or the result omits what a skipped folder holds |
+| FR6 | The component's own interaction and accessibility checks run against the copy | Keyboard, pointer, screen-reader tree | A check that passes on the package fails on the copy |
+| FR7 | The required test lane's swizzle proof and the release-time proof; both cover Core's list and every integration package's components through `--package` | A change to component source; a change to the swizzle copy; an unrelated change; Core, Lab, Charts, RichText, Vega | An offered component missing from the proof, a failure that does not block, a new required context, the proof adding wall-clock time to the slowest required check, or the proof pushing its job past the pull-request time budget |
Known verification gap: only FR3's shared-context checks (`sharedContexts.test.tsx`) exist; the other rows have no check on `main`.
diff --git a/packages/core/api-report.md b/packages/core/api-report.md
index 3a61846646..7e0ba66991 100644
--- a/packages/core/api-report.md
+++ b/packages/core/api-report.md
@@ -7811,7 +7811,7 @@ interface MarkdownPluginCapabilities
type MarkdownPluginData = MarkdownAstDataValue
type MarkdownPluginDefinition<Name extends string, Node extends MarkdownExtensionNode<Name> = never> = MarkdownSyntaxPluginDefinition<Name, Node> | MarkdownTransformPluginDefinition<Name, Node>
interface MarkdownPluginEntry<Node extends MarkdownExtensionNode = MarkdownExtensionNode>
- [markdownPluginNode]: Node
+ @astryxdesign/core/markdown-plugin-node/v1: Node
apiVersion: 1
name: string
interface MarkdownSourceDecoration
@@ -7855,7 +7855,7 @@ interface MarkdownTokenizerInput
offset: number
source: string
interface MarkdownTransform<Node extends MarkdownExtensionNode = never>
- [markdownTransformNode]?: Node
+ @astryxdesign/core/markdown-transform-node/v1?: Node
interface MarkdownTransformContext
display: 'inline' | 'block'
isFinal: boolean
diff --git a/packages/core/src/Markdown/plugins/protocol.ts b/packages/core/src/Markdown/plugins/protocol.ts
index 7a6a61fa90..4af8fa9a5d 100644
--- a/packages/core/src/Markdown/plugins/protocol.ts
+++ b/packages/core/src/Markdown/plugins/protocol.ts
@@ -152,14 +152,16 @@ export function getMarkdownHelperOwnership(
: {pluginName, hasRenderer, sourceUnchanged};
}
-declare const markdownTransformNode: unique symbol;
-
export interface MarkdownTransform<Node extends MarkdownExtensionNode = never> {
(
document: MarkdownAstRoot<MarkdownExtensionNode>,
context: MarkdownTransformContext,
): MarkdownAstRoot<MarkdownExtensionNode>;
- readonly [markdownTransformNode]?: Node;
+ /**
+ * A type-only member that carries the node type; it is never present. Its
+ * shared key lets a swizzled copy's transform type match the package's.
+ */
+ readonly '@astryxdesign/core/markdown-transform-node/v1'?: Node;
}
const markdownTransformClaim = Symbol('MarkdownTransformClaim');
@@ -268,15 +270,17 @@ export type MarkdownPluginDefinition<
| MarkdownSyntaxPluginDefinition<Name, Node>
| MarkdownTransformPluginDefinition<Name, Node>;
-declare const markdownPluginNode: unique symbol;
-
/** Opaque, covariant entry safe to store in heterogeneous plugin lists. */
export interface MarkdownPluginEntry<
Node extends MarkdownExtensionNode = MarkdownExtensionNode,
> {
readonly name: string;
readonly apiVersion: 1;
- readonly [markdownPluginNode]: Node;
+ /**
+ * A type-only member that carries the node type; it is never present. Its
+ * shared key lets a swizzled copy's entry type match the package's.
+ */
+ readonly '@astryxdesign/core/markdown-plugin-node/v1': Node;
}
export type MarkdownNodeOf<Entry> =
diff --git a/packages/core/src/utils/sharedBrands.test.ts b/packages/core/src/utils/sharedBrands.test.ts
index 6eb028606a..4639265fe6 100644
--- a/packages/core/src/utils/sharedBrands.test.ts
+++ b/packages/core/src/utils/sharedBrands.test.ts
@@ -52,6 +52,8 @@ describe('brands a swizzled copy shares with the package', () => {
['motion/animatedLayout', 'AnimatedLayout'],
['CodeBlock/grammar', 'CodeLanguage'],
['SnapPaging/snapPagingValue', 'SnapPaging'],
+ ['Markdown/plugins/protocol', 'MarkdownPluginEntry'],
+ ['Markdown/plugins/protocol', 'MarkdownTransform'],
];
fs.writeFileSync(
check,