Skip to content

fix(gsplat): sort worker ReferenceError after esbuild migration#8808

Merged
mvaligursky merged 1 commit into
mainfrom
mv-gsplat-sort-worker-class-fields
May 29, 2026
Merged

fix(gsplat): sort worker ReferenceError after esbuild migration#8808
mvaligursky merged 1 commit into
mainfrom
mv-gsplat-sort-worker-class-fields

Conversation

@mvaligursky

Copy link
Copy Markdown
Contributor

Fixes a worker crash on first gsplat sort in minified UMD/min builds — only the unified ESM rel build (playcanvas.mjs) escaped because it sets preserveClassFields.

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. This regressed after the rollup+swc → esbuild migration in #8722; swc had inlined the fields directly as this.x = ….

Changes:

  • Move binWeights, bitsPerBin, weightByDistance, lastCameraBin, lastBucketCount from class field declarations into the constructor as plain this.x = … assignments — keeps the class self-contained when stringified.
  • Add a constructor-doc note explaining the constraint so the next person doesn't reintroduce class fields here.

Fixes #8806.

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 mvaligursky self-assigned this May 29, 2026
@mvaligursky mvaligursky merged commit e51507f into main May 29, 2026
8 checks passed
@mvaligursky mvaligursky deleted the mv-gsplat-sort-worker-class-fields branch May 29, 2026 10:14
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>
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.

v2.19.0: GSplat sorter worker throws "n is not defined" on first render frame (WebGPU)

1 participant