scala-js / scala-js-env-jsdom-nodejs

Node.js with jsdom environment for Scala.js
BSD 3-Clause "New" or "Revised" License
8 stars 10 forks source link

Fix #42: Hack around React's development mode error triggering hack. #45

Closed sjrd closed 4 years ago

sjrd commented 4 years ago

React's development mode has a funny way of triggering errors, which tries to convince that exceptions are uncaught (for their development tools to report them) even though React catches them for the "error boundaries" feature.

Since our jsdom handler reports uncaught exceptions as hard failures that fail the run, this creates a very bad interaction where every caught-but-not-really exception crashes the run.

We hack around this hack by detecting when our error handler is in fact called by React's own hack. In that case, we ignore the uncaught exception, and proceed with normal execution.

We add a test that actually uses React's error boundaries, and makes sure that the React component can still detect the error and its error message.

sjrd commented 4 years ago

@japgolly It would be really nice if you could test this for your use case. You can do with:

  1. Checkout the branch of this PR
  2. Run sbt scalajs-env-jsdom-nodejs/publishLocal
  3. Change "org.scala-js" %% "scalajs-env-jsdom-nodejs" % "1.1.0-SNAPSHOT" in your project/plugins.sbt to use version 1.1.0-SNAPSHOT instead
  4. Run your tests