Skip to content

fix: deduplicate three.js instance bundled by jsroot#817

Merged
EdwardMoyse merged 1 commit into
HSF:mainfrom
remo-lab:fix/duplicate-threejs-instance
Mar 11, 2026
Merged

fix: deduplicate three.js instance bundled by jsroot#817
EdwardMoyse merged 1 commit into
HSF:mainfrom
remo-lab:fix/duplicate-threejs-instance

Conversation

@remo-lab
Copy link
Copy Markdown
Contributor

@remo-lab remo-lab commented Mar 7, 2026

Summary

Fixes #655

JSROOT bundles its own copy of three.js (v174) directly inside
jsroot/modules/three.mjs (~59K lines). This results in a second
three.js instance being loaded at runtime alongside Phoenix's
three.js (v178), triggering the warning:


WARNING: Multiple instances of Three.js being imported.

Having multiple instances of three.js can lead to issues such as:

  • memory leaks
  • instanceof check failures across module boundaries
  • other undefined behavior at runtime

Fix

  • Added a Yarn resolution in the root package.json to enforce a
    single three@~0.178.0 version across dependencies.

  • Added a postinstall patch script
    scripts/patch-jsroot-three.js that replaces JSROOT's inlined
    three.js implementation with a simple re-export:

export * from 'three'

The patch runs automatically during yarn install, ensuring the
fix is applied transparently without requiring any manual steps.


Verification

  • Confirmed that only one REVISION (178) exists in the bundled
    vendor.js. The duplicate version (174) is no longer present.

  • The console warning no longer appears when running Phoenix on
    my localhost. I have attached a video below showing a comparison
    between the official Phoenix demo website and my local
    environment after applying the fix.

Recording.2026-03-07.155825.mp4

@remo-lab
Copy link
Copy Markdown
Contributor Author

remo-lab commented Mar 7, 2026

@EdwardMoyse , I’ve opened this PR to address the duplicate Three.js instance issue. I’ve verified locally that the warning no longer appears. Would really appreciate a review when you have time. Thanks!

Closes HSF#655

Signed-off-by: remo-lab <remopanda7@gmail.com>
@remo-lab remo-lab force-pushed the fix/duplicate-threejs-instance branch from ea4404f to 8e13cbc Compare March 7, 2026 10:36
@remo-lab
Copy link
Copy Markdown
Contributor Author

remo-lab commented Mar 9, 2026

@EdwardMoyse , shall i update anything on this pr?

@EdwardMoyse EdwardMoyse merged commit f8e05ff into HSF:main Mar 11, 2026
2 checks passed
@EdwardMoyse
Copy link
Copy Markdown
Member

Thanks very much for this - obviously the preferred solution would be for jsroot to fix this on their side, but in the meantime this seems like a good idea.

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.

WARNING: Multiple instances of Three.js being imported.

2 participants