Repository navigation
d2js: fix WASM failing to start in Safari 27 workers - #2960
Closed
nelsonjchen wants to merge 2 commits into
Closed
nelsonjchen wants to merge 2 commits into
nelsonjchen wants to merge 2 commits into
Conversation
lib/textmeasure imported github.com/yuin/goldmark/extension for
Strikethrough and Table. That package compiles its linkify URL regexps
at init; their {1,256} repetition recurses deeply in regexp/syntax and
overflows the smaller JS stack of a Safari 27 Web Worker. The Go program
died before registering self.d2, d2.js still reported ready, and every
call failed with "undefined is not an object (evaluating 'd2.encode')".
Copy only the Strikethrough and Table extensions from goldmark v1.8.5
into lib/textmeasure/internal/gmext, add a test that keeps
goldmark/extension out of the d2js WASM dependency graph, and record the
goldmark MIT notice.
Also make the d2.js workers reject init with "D2 WASM failed to
initialize: <reason>" when the Go program fails to register d2, instead
of reporting ready with no API.
Fixes d2lang#2956
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
|
Closing in favor of #2965 |
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 #2956. Tracked on the playground side in d2lang/d2-playground#113.
Problem
In Safari 27.2, play.d2lang.com and anything else built on d2.js fail with
undefined is not an object (evaluating 'd2.encode'). This isn't a d2.js 0.1.34 / D2 v0.9.0 regression: 0.1.33 fails the same way.lib/textmeasureimportsgithub.com/yuin/goldmark/extensionfor Strikethrough and Table. That package compiles its linkify URL regexps at package init, and their{1,256}repetition makesregexp/syntax.(*compiler).compilerecurse deeply. A Safari 27 Web Worker has a smaller JS stack than the main thread, so init throwsRangeError: Maximum call stack size exceeded. The Go program dies before it registersself.d2, but d2.js still reportsready.Changes
lib/textmeasure/internal/gmext: copies only the Strikethrough and Table extensions from goldmark v1.8.5 (MIT; added toTHIRD_PARTY_NOTICES.txtand the d2js copy).goldmark/extensionno longer links into the WASM;goldmark/extension/astis a separate package and stays.gmext/deps_test.go: fails if theGOOS=jsd2js dependency graph picks upgoldmark/extensionagain.readynow rejects withD2 WASM failed to initialize: <reason>when the Go program doesn't registerd2, instead of resolving with no API.next.mdand the d2.js changelog.Latest goldmark (v1.8.7) still compiles these regexps eagerly. An upstream change to make them lazy would let us delete the vendored copy later.
Testing
version/compile/render/encodeall work on a markdown diagram with a table and strikethrough.readyrejects withD2 WASM failed to initialize: Maximum call stack size exceeded.go test ./lib/textmeasure/... ./d2renderers/... ./e2etests/... ./d2lib/... ./d2js/...pass;bun test test/unitpasses (52/52).🤖 Generated with Claude Code