Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Import generation has unresolved correctness issues that can produce invalid MDX.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
Addresses #733 by extending MDXEditor’s export pipeline to generate root imports for JSX inside directives and tables.
Changes:
- Collect component references from exported MDAST subtrees.
- Suppress newly generated imports during table-cell export.
- Add regression tests and an interactive reproduction example.
| File | Description |
|---|---|
tests/browser/nested-jsx-imports.spec.ts |
Tests insertion, import deduplication, and save/reload. |
src/test/nested-jsx-imports.test.tsx |
Tests subtree traversal and import selection. |
src/test/nested-jsx-imports-integration.test.tsx |
Tests nested-editor and table-cell exports. |
src/plugins/table/TableEditor.tsx |
Disables fresh imports during cell export. |
src/exportMarkdownFromLexical.ts |
Collects descriptor-backed JSX references from MDAST. |
src/examples/bug-733.tsx |
Adds an interactive nested-JSX reproduction. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // Lexical children, so their JSX references never reach the JSX visitor. | ||
| if (addImportStatements) { | ||
| const registerNestedComponents = (node: Mdast.Nodes) => { | ||
| if ((node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement') && node.name !== null && !isMdastHTMLNode(node)) { |
Comment on lines
+220
to
+221
| if (descriptor?.source) { | ||
| registerReferredComponent(node.name) |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #733.
Problem
Directives and tables export stored MDAST subtrees directly, so JSX inside them never reaches the JSX visitor that registers component imports. Inserting a descriptor-backed component into an admonition therefore saves the component without its root-level import.
#734 preserved existing imports, but left newly inserted nested components unresolved. This change keeps that existing-import behavior and supplies the missing root imports.
Changes
bug-733example, and browser coverage for insertion, shared root/nested references, table contents, and save/reload.Verification
Three-browser red/green run:
npm run typecheck,npm run lint,npm run test:once, andnpm run buildpassed. Unit suite: 136 passed, with the existing 1 skipped and 1 todo unchanged.122347cmakes the missing-import assertion fail in Chromium, Firefox, and WebKit.The six files in this PR match the tested file blobs. The fork-only validation workflow and Playwright configuration are not included.