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

slinky-hot prevents to load pages in Scala 3 #663

Open
KapStorm opened this issue Aug 2, 2023 · 5 comments
Open

slinky-hot prevents to load pages in Scala 3 #663

KapStorm opened this issue Aug 2, 2023 · 5 comments
Labels
Milestone

Comments

@KapStorm
Copy link

KapStorm commented Aug 2, 2023

We are migrating our Slinky project from Scala 2 to Scala 3 and we have problems when we initialize slinky-hot, causing pages to fail to load and print console.errors in the browser console

To reproduce this we are calling hot.initialize() in the Main file. Removing hot.initialize() solves the load problem

Our project in the scala 3 branch https://github.com/wiringbits/scala-webapp-template/tree/scala3

Browser console errors

image

Main.scala

@JSImport("js/index.css", JSImport.Default)
@js.native
object IndexCSS extends js.Object

object Main {
  val css = IndexCSS

  def main(argv: Array[String]): Unit = {
    if (LinkingInfo.developmentMode) {
      hot.initialize()
    }

    val scheduler = monix.execution.Scheduler.global
    val $authState = Var[AuthState](AuthState.Unauthenticated)(scheduler)
    val $lang = Var[I18nLang](I18nLang.English)(scheduler)
    val ctx = AppContext(
      API(),
      $authState,
      $lang,
      Email.trusted("[email protected]"),
      "+52 (999) 9999 999",
      org.scalajs.macrotaskexecutor.MacrotaskExecutor
    )
    val app = ErrorBoundaryComponent(
      ErrorBoundaryComponent.Props(
        child = App.component(App.Props(ctx)),
        renderError = e => ErrorBoundaryInfo(e)
      )
    )

    ReactDOM.render(app, dom.document.getElementById("root"))
  }
}
@KapStorm
Copy link
Author

KapStorm commented Aug 2, 2023

Looking at the issues I found the same issue: #547

@shadaj
Copy link
Owner

shadaj commented Aug 2, 2023

Interesting, which version of Slinky are you using? You seem to be running into the exact same issue, but it should be fixed in the latest release.

@AlexITC
Copy link
Contributor

AlexITC commented Aug 2, 2023

0.7.3 (ref), my understanding is that the issue should be fixed in this version.

@shadaj
Copy link
Owner

shadaj commented Aug 12, 2023

That is very strange, might be some weird interaction between the proxied hot-reloading class. I'll try to test locally when I get a chance, might be a bit before I can get to it though unfortunately.

In the meantime, is using React Refresh via https://github.com/pmmmwh/react-refresh-webpack-plugin an option? It does miss out on preserving component state but that's what I use via Next for the docs site. The current hot reloading support depends on a very old library, so might be worth investing in Refresh for the future.

@shadaj shadaj added the bug label Aug 12, 2023
@shadaj shadaj added this to the v0.7.5 milestone Aug 12, 2023
@AlexITC
Copy link
Contributor

AlexITC commented Aug 12, 2023

In the meantime, is using React Refresh via https://github.com/pmmmwh/react-refresh-webpack-plugin an option?

We could give it a try, we don't preserve component state because we use functional components.

Thanks for the hint.

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

No branches or pull requests

3 participants