♻️ refactor: share LiteXML command identities across bundles via a pure module#168
Merged
Merged
Conversation
…re module The package ships two independently-bundled entries — the browser build (`index`/`react`/`renderer`) and the node build (`headless`). Each previously inlined its own `createCommand(...)` call for the LiteXML commands, so a command obtained from one entry and dispatched onto an editor registered by the other silently no-ops (Lexical matches command listeners by object reference, not by the string label). Isolate every LiteXML command identity (+ the `DiffAction` enum) into a new side-effect-free `plugins/litexml/command/symbols.ts`, re-exported from the existing command modules so nothing else changes. Emit it as a dedicated chunk in the node build and expose it through a new `@lobehub/editor/litexml-commands` subpath, so: - both bundles import the same emitted `symbols.js` → one runtime identity; - the commands can be imported on the server without pulling the DOM-dependent editor bundle (the module only imports `createCommand` from `lexical`). This lets consumers dispatch `LITEXML_*_COMMAND` directly on a `HeadlessEditor` kernel instead of routing through wrapper methods. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
github-actions Bot
pushed a commit
that referenced
this pull request
Jun 6, 2026
### [Version 4.16.1](v4.16.0...v4.16.1) <sup>Released on **2026-06-06**</sup> #### ♻ Code Refactoring - **misc**: Share LiteXML command identities across bundles via a pure module. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### Code refactoring * **misc**: Share LiteXML command identities across bundles via a pure module, closes [#168](#168) ([f7d70c1](f7d70c1)) </details> <div align="right"> [](#readme-top) </div>
Member
|
🎉 This PR is included in version 4.16.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
💻 Change Type
🔀 Description of Change
This package ships two independently-bundled entries — the browser build (
index/react/renderer) and the node build (headless). Each one previously inlined its owncreateCommand(...)call for the LiteXML commands.Because Lexical's
dispatchCommandmatches listeners by object reference, not by the string label, a command obtained from one entry and dispatched onto an editor registered by the other silently no-ops — same label, different object.Concretely, before this PR (
v4.16.0build output):es/plugins/litexml/command/index.jsholdscreateCommand("LITEXML_MODIFY_COMMAND")(used by the browser bundles)es/headless.jsinlines a secondcreateCommand("LITEXML_MODIFY_COMMAND")→ two distinct objects. Dispatching the browser command onto a
HeadlessEditorkernel does nothing.🛠 How it's fixed
DiffActionenum) into a new side-effect-free modulesrc/plugins/litexml/command/symbols.ts(it only importscreateCommandfromlexical). The existingcommand/index.tsandcommand/diffCommand.tsre-export from it, so no other source changes.tsdown.config.ts) soheadless.jsreferences./plugins/litexml/command/symbols.jsinstead of inlining a copy. The unbundled browser build already resolves to the same emitted file.@lobehub/editor/litexml-commands, pointing at that samesymbols.js.Result:
symbols.js→ a single runtime identity for each command.@lobehub/editor/litexml-commands) without pulling the DOM-dependent editor bundle.LITEXML_*_COMMANDdirectly on aHeadlessEditorkernel instead of routing through wrapper methods.🧪 How to Test
pnpm run ci+pnpm run testare green (301 tests). Verified against the built output:The subpath command (imported from a DOM-free path) mutates a
HeadlessEditorexactly as the in-bundle command would — proving the kernel and the subpath share one identity.📝 Additional Information
LITEXML_*exports from.,./headless, and./plugins/litexmlare unchanged.@lobechat/editor-runtime) currently works around the duplicate identity with a server-side LiteXML "adapter". With this subpath, that workaround can be removed.🤖 Generated with Claude Code