Skip to content

Port upstream Prism dependency order fix#69

Open
Renakoni wants to merge 1 commit into
mainfrom
sync/upstream-4861-prism-dependency-order
Open

Port upstream Prism dependency order fix#69
Renakoni wants to merge 1 commit into
mainfrom
sync/upstream-4861-prism-dependency-order

Conversation

@Renakoni

@Renakoni Renakoni commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Upstream

Ports marktext/marktext#4861: marktext/marktext#4861

Upstream fixed Muya's Prism language loader so dependency languages are loaded in the order Prism expects. The concrete failure is cold-loading C++ before C: prism-cpp extends the c grammar, so a parallel/racy load can fail before the dependency exists.

Android relevance

Android uses this Muya Prism path for editor code highlighting in the WebView. The same dependency-order race applies here on cold grammar loads, especially C/C++ and other grammars with Prism dependencies.

Changes

  • Replace the deferred-status collection with an ordered async loadComponent callback.
  • Pass Prism's dependency loader explicit series and parallel chainers so dependent components are awaited before dependents run.
  • Keep returned load statuses for loaded, cached, and noexist outcomes.
  • Add a focused regression test that loads cpp, asserts c is registered before cpp, and verifies tokenization does not throw.
  • Android-specific correction: resolve Prism component dynamic imports from Muya's package location with ../../../node_modules/prismjs/components/prism-*.js. The previous glob made the focused Vitest run unable to resolve several Prism modules such as c, latex, and yaml; this path keeps the dynamic import map tied to the actual dependency under this workspace.

Verification

  • pnpm --dir third_party/muya exec vitest run src/utils/prism/__tests__/loadLanguageDependencyOrder.spec.ts
  • pnpm build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant