fix(gsplat): sort worker ReferenceError after esbuild migration#8808
Merged
Conversation
GSplatSortBinWeights is stringified via toString() and injected into the unified sorter's Worker blob. With esbuild's target: 'es2020', public class fields are transpiled into __publicField() helper calls (minified to n). The helper lives only in the main bundle, so when the class runs inside the worker the constructor throws "ReferenceError: n is not defined" on its first field assignment. Move all five instance fields into the constructor as plain this.x = ... assignments so the class stays self-contained when stringified. Fixes #8806.
mvaligursky
added a commit
that referenced
this pull request
May 29, 2026
GSplatSortBinWeights is stringified via toString() and injected into the unified sorter's Worker blob. With esbuild's target: 'es2020', public class fields are transpiled into __publicField() helper calls (minified to n). The helper lives only in the main bundle, so when the class runs inside the worker the constructor throws "ReferenceError: n is not defined" on its first field assignment. Move all five instance fields into the constructor as plain this.x = ... assignments so the class stays self-contained when stringified. Fixes #8806. Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
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 a worker crash on first gsplat sort in minified UMD/min builds — only the unified ESM rel build (
playcanvas.mjs) escaped because it setspreserveClassFields.GSplatSortBinWeightsis stringified viatoString()and injected into the unified sorter's Worker blob. With esbuild'starget: 'es2020', public class fields are transpiled into__publicField()helper calls (minified ton). The helper lives only in the main bundle, so when the class runs inside the worker the constructor throwsReferenceError: n is not definedon its first field assignment. This regressed after the rollup+swc → esbuild migration in #8722; swc had inlined the fields directly asthis.x = ….Changes:
binWeights,bitsPerBin,weightByDistance,lastCameraBin,lastBucketCountfrom class field declarations into the constructor as plainthis.x = …assignments — keeps the class self-contained when stringified.Fixes #8806.