Error rendering component with React.Suspense
See original GitHub issueGot an error with React.Suspense
(React 16.7.0). Am I missing something?
import japgolly.scalajs.react._
import japgolly.scalajs.react.vdom.html_<^._
import org.scalajs.dom
object App {
def main(args: Array[String]): Unit = {
def body = {
val main = AsyncCallback
.pure(<.div(^.color := "#070", "Async load complete."))
.delayMs(2000)
React.Suspense(
fallback = <.div(^.color.red, "Loading..."),
asyncBody = main
)
}
val Main =
ScalaComponent
.builder[Unit]("Main")
.stateless
.render_(<.div(^.fontSize := "175%", body))
.build
val container = dom.document.getElementById("root")
Main().renderIntoDOM(container)
}
}
Browser stack trace:

Replication repo: https://github.com/allantl/scalajs-react-suspense
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Suspense for Data Fetching (Experimental) - React
With Suspense, handling fetching errors works the same way as handling rendering errors — you can render an error boundary anywhere to “catch”...
Read more >All You Need To Know About React Suspense - CopyCat Blog
A React fallback UI is a component rendered when an error occurs within React component tree or when a component is suspended due...
Read more >10 Minute Read: Understanding React Suspense with Visuals ...
Any time a child component throws an error, such as a failed network request, a wrapping Error Boundary component can toggle its rendering...
Read more >React Suspense and Error Boundary - Neethack
In React 16.6, React is adding the Suspense component that it can render fallback while the app is loading javascript or fetching API....
Read more >A React component suspended while rendering, but no ...
It was using <Suspense /> element in the component but I removed it. Then application is crashed with above error. Is there any...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is because
japgolly.scalajs.react.raw.Suspense
is defined like this:According to the documentation for the relevant overload of
JSImport
:That means that if compiling for an environment without modules (such as a legacy browser environment) then it’s (correctly) interpreted as an alias for
React.Suspense
, but if compiled for an environment with modules then it gets interpreted asimport * as Suspense from "react"
, which is obviously wrong.I’ll send a PR as soon as I’ve verified that this fixes the issue.
Thanks!