Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error when used on server side via SVGRenderer #398

Merged
merged 4 commits into from
Jan 19, 2025

Conversation

DrSensor
Copy link
Contributor

@DrSensor DrSensor commented Jan 19, 2025

Why

When used on server side or test runner (without any bundling), it cause this kind of error even though I'm using SVGRenderer instead of the default renderer.

   Error: 
        at <anonymous> (/home/runner/work/circuit-to-svg/circuit-to-svg/node_modules/three-stdlib/libs/lottie.js:1052:7)
        at <anonymous> (/home/runner/work/circuit-to-svg/circuit-to-svg/node_modules/three-stdlib/libs/lottie.js:1054:14)
        at <anonymous> (/home/runner/work/circuit-to-svg/circuit-to-svg/node_modules/three-stdlib/libs/lottie.js:1248:12)
        at /home/runner/work/circuit-to-svg/circuit-to-svg/node_modules/three-stdlib/libs/lottie.js:13924:10
  1047 |     var proxyImage = function() {
  1048 |       var canvas = createTag("canvas");
  1049 |       canvas.width = 1;
  1050 |       canvas.height = 1;
  1051 |       var ctx = canvas.getContext("2d");
  1052 |       ctx.fillStyle = "rgba(0,0,0,0)";
               ^
  TypeError: null is not an object (evaluating 'ctx.fillStyle = "rgba(0,0,0,0)"')
        at <anonymous> (/home/runner/work/circuit-to-svg/circuit-to-svg/node_modules/three-stdlib/libs/lottie.js:1052:7)
        at <anonymous> (/home/runner/work/circuit-to-svg/circuit-to-svg/node_modules/three-stdlib/libs/lottie.js:1054:14)
        at <anonymous> (/home/runner/work/circuit-to-svg/circuit-to-svg/node_modules/three-stdlib/libs/lottie.js:1248:12)
        at /home/runner/work/circuit-to-svg/circuit-to-svg/node_modules/three-stdlib/libs/lottie.js:13924:10

What

The problem cause by context2d being accessed eagerly in IIFE. It shouldn't be a problem to defer it at instantiation.

Checklist

  • Documentation updated
  • Storybook entry added
  • Ready to be merged

Copy link

codesandbox-ci bot commented Jan 19, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

DrSensor added a commit to DrSensor/tscircuit_cirtuit-to-svg that referenced this pull request Jan 19, 2025
@CodyJasonBennett
Copy link
Member

CodyJasonBennett commented Jan 19, 2025

Which environment is this? We have a very loose check for SSR at the top of the lottie file with typeof navigator === 'undefined' || typeof document === 'undefined', but this may need to be hardened. We also check for typeof document.createElement === 'function' in some environments which may work here.

@DrSensor
Copy link
Contributor Author

we are using bun with happy-dom as DOM emulation

@DrSensor
Copy link
Contributor Author

@CodyJasonBennett I've revert the change in favor of hardened the if condition.

@CodyJasonBennett CodyJasonBennett merged commit 5b1448e into pmndrs:main Jan 19, 2025
3 checks passed
Copy link

🎉 This PR is included in version 2.35.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants