Skip to content

feat(editor-preview-asyncapi): offload AsyncAPI parsing to web worker#5786

Open
robert-hebel-sb wants to merge 11 commits into
mainfrom
feat/asyncapi-parser-web-worker
Open

feat(editor-preview-asyncapi): offload AsyncAPI parsing to web worker#5786
robert-hebel-sb wants to merge 11 commits into
mainfrom
feat/asyncapi-parser-web-worker

Conversation

@robert-hebel-sb
Copy link
Copy Markdown
Contributor

@robert-hebel-sb robert-hebel-sb commented May 18, 2026

Summary

  • Moves AsyncAPI parsing off the main thread into a dedicated Comlink-backed web worker (worker/asyncapi-parser.worker.ts) with a lazy singleton proxy (worker/parser-worker-proxy.ts) — spawned only on the first parse call
  • Worker returns plain JSON (document.json()) to satisfy structured-clone constraints; AsyncAPIDocument is reconstructed cheaply on the main thread via toAsyncAPIDocument()
  • EditorPreviewAsyncAPI rewritten in TypeScript and updated to retain the previous render during re-parses, eliminating the blank-flash on each keystroke (fixes regression caused by selectIsParseInProgress returning false when parseResult is non-null)
  • Vite ESM/UMD builds extended with an asyncapiParserWorkerConfig build step; RewriteEditorWorkerImport updated to intercept the ?worker import for library consumers

Test plan

  • Load an AsyncAPI 2.x example — preview renders correctly
  • Type in the editor — preview stays visible during re-parse (no blank flash)
  • Switch to an OpenAPI spec — AsyncAPI preview hidden; switch back — preview re-renders
  • npm run lint passes
  • npx playwright test passes (60 tests)
  • npm run build:bundle:esm and npm run build:bundle:umd produce asyncapi-parser.worker.js in dist

🤖 Generated with Claude Code

@robert-hebel-sb robert-hebel-sb marked this pull request as draft May 18, 2026 12:54
@robert-hebel-sb robert-hebel-sb changed the base branch from main to robert-hebel-sb/vite-poc-2 May 18, 2026 12:55
@robert-hebel-sb robert-hebel-sb added enhancement New feature or request javascript Pull requests that update Javascript code labels May 18, 2026
Base automatically changed from robert-hebel-sb/vite-poc-2 to main May 19, 2026 10:19
@robert-hebel-sb robert-hebel-sb force-pushed the feat/asyncapi-parser-web-worker branch from 4e3a746 to 6a117b7 Compare May 20, 2026 07:37
@robert-hebel-sb robert-hebel-sb force-pushed the feat/asyncapi-parser-web-worker branch from 4749fb0 to f895ea1 Compare May 20, 2026 07:42
robert-hebel-sb and others added 7 commits May 20, 2026 10:13
Add asyncapiParserWorkerConfig to ESM and UMD build scripts, register
the virtual constructor module, and add fs-shim + nodePolyfills to
resolve @asyncapi/parser's Node.js fs imports in the browser bundle.
Update actions.js to consume the worker proxy and reconstruct the
AsyncAPI document via toAsyncAPIDocument.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rrors

selectIsParseInProgress checked parseErrors === null via the normalizing
selectParseErrors selector, which always returns [] — never null. The
condition was always false, so waitUntil in monaco.contribution.js
resolved immediately with stale state and set stale markers that
persisted until the next edit.

Fix: derive selectIsParseInProgress from parseStatus alone.
Also fix showFailure in EditorPreviewAsyncAPI to check
parseErrors.length > 0 instead of parseErrors !== null, which was
likewise always true and caused the error pane to show on initial load.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Allow consumers to pass parserOptions (e.g. __unstable.resolver) to the
AsyncAPI parser worker. Resolver read/canRead functions are wrapped with
Comlink.proxy() in parser-worker-proxy so they execute on the main
thread, retaining access to store, document, and config. A Comlink
transferHandler for urijs Uri objects handles the Uri→string conversion
automatically when the parser passes URI arguments across the worker
boundary.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add asyncapi-parser.worker to the workers overview table, add a
dedicated section covering Comlink proxy loading, custom parserOptions
(including Comlink.proxy() resolver pattern), the Uri transfer handler,
and ESM/UMD build outputs. Update README webpack entry points,
CopyWebpackPlugin patterns, and exports block.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…orker-proxy

Use spread on resolver to avoid listing properties explicitly, and
extract wrappedResolvers before the return to reduce nesting depth.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move the inline fs-shim plugin definition into vite/plugins/fs-shim.js
and replace the three inline copies in vite.config.app.js and the ESM/
UMD worker configs with an import of the shared fsShim() factory.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@robert-hebel-sb robert-hebel-sb marked this pull request as ready for review May 20, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request javascript Pull requests that update Javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants