japgolly/scalajs-react

Need for Java class ConstantDesc w/ StateSnapshot value access in Event and Monocle (and int!)

DroneEnthusiast opened this issue · 1 comments

Hello! Little linking bug:

[info] Fast optimizing C:\Users\Drone\repro\dist\scripts
[error] Referring to non-existent class java.lang.constant.ConstantDesc
[error]   called from private Inner$Backend.render$$anonfun$1$$anonfun$1(japgolly.scalajs.react.facade.SyntheticEvent,InnerStatus)InnerStatus
[error]   called from private Inner$Backend.render$$anonfun$2(Inner$Props,japgolly.scalajs.react.facade.SyntheticEvent)japgolly.scalajs.react.callback.Trampoline
[error]   called from private Inner$Backend.render$$anonfun$adapted$1(Inner$Props,japgolly.scalajs.react.facade.SyntheticEvent)java.lang.Object
[error]   called from Inner$Backend.render(Inner$Props)japgolly.scalajs.react.vdom.TagOf
[error]   called from private Inner$.$init$$$anonfun$1(japgolly.scalajs.react.component.builder.LifecycleF$RenderScope)japgolly.scalajs.react.vdom.VdomNode
[error]   called from constructor Inner$.<init>()void
[error]   called from Outer$Backend.render(java.lang.Void,Outer$Status)japgolly.scalajs.react.component.Js$UnmountedWithRoot
[error]   called from private Outer$.$init$$$anonfun$1(japgolly.scalajs.react.component.builder.LifecycleF$RenderScope)japgolly.scalajs.react.vdom.VdomNode
[error]   called from constructor Outer$.<init>()void
[error]   called from constructor Init$.<init>()void
[error]   exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error]   Inner$Backend
[error]   Outer$Backend
[error] Referring to non-existent class java.lang.constant.ConstantDesc
[error]   called from private Inner$Backend.render$$anonfun$1$$anonfun$1(japgolly.scalajs.react.facade.SyntheticEvent,InnerStatus)InnerStatus
[error]   called from private Inner$Backend.render$$anonfun$2(Inner$Props,japgolly.scalajs.react.facade.SyntheticEvent)japgolly.scalajs.react.callback.Trampoline
[error]   called from private Inner$Backend.render$$anonfun$adapted$1(Inner$Props,japgolly.scalajs.react.facade.SyntheticEvent)java.lang.Object
[error]   called from Inner$Backend.render(Inner$Props)japgolly.scalajs.react.vdom.TagOf
[error]   called from private Inner$.$init$$$anonfun$1(japgolly.scalajs.react.component.builder.LifecycleF$RenderScope)japgolly.scalajs.react.vdom.VdomNode
[error]   called from constructor Inner$.<init>()void
[error]   called from Outer$Backend.render(java.lang.Void,Outer$Status)japgolly.scalajs.react.component.Js$UnmountedWithRoot
[error]   called from private Outer$.$init$$$anonfun$1(japgolly.scalajs.react.component.builder.LifecycleF$RenderScope)japgolly.scalajs.react.vdom.VdomNode
[error]   called from constructor Outer$.<init>()void
[error]   called from constructor Init$.<init>()void
[error]   exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error]   Inner$Backend
[error]   Outer$Backend
[error] There were linking errors
[error] (Compile / fastLinkJS) There were linking errors

with dependencies

    "com.github.japgolly.scalajs-react" %%% "core" % "2.0.0-RC3",
    "com.github.japgolly.scalajs-react" %%% "extra" % "2.0.0-RC3",
    "com.github.japgolly.scalajs-react" %%% "extra-ext-monocle3" % "2.0.0-RC3",

and code

case class InnerStatus(cantRelyOn: Int, intsTheseDays: Int)
given Reusability[InnerStatus] = Reusability.never[InnerStatus]

object Outer:
  case class Status(innerStatus: InnerStatus)
  object Status:
    val innerStatus =
      Lens[Status, InnerStatus](_.innerStatus)(sp => _.copy(innerStatus = sp))

  class Backend(scope: BackendScope[Unit, Status]):
    val innerStatusStatusSnapshot =
      StateSnapshot.withReuse.zoomL(Status.innerStatus).prepareVia(scope)
    def render(u: Unit, status: Status) =
      Inner(innerStatusStatusSnapshot(status))

  val component = ScalaComponent.builder[Unit]
    .initialState(
      Status(InnerStatus(12, 13)))
    .renderBackend[Backend]
    .build

  def apply() =
    component()

object Inner:
  case class Props(ss: StateSnapshot[InnerStatus])
  class Backend(scope: BackendScope[Props, Unit]):
    def render(p: Props) =
      <.input(
        ^.onInput ==> { (e: ReactEventFromInput) =>
          p.ss.modState{ s =>
            val result = {
              if
                e.target.valueAsNumber >= 21
              then
                s.intsTheseDays
              else
                e.target.valueAsNumber
            }.toString
            e.target.value = result
            s.copy(intsTheseDays = result.toInt)
          }
        },
      )

  val component = ScalaComponent.builder[Props]
    .stateless
    .renderBackend[Backend]
    .build

  def apply(ss: StateSnapshot[InnerStatus]) =
    component(Props(ss))

@JSExportTopLevel(name = "Init")
object Init:
  Outer()

Thank you!

Hey @DroneEnthusiast , thanks for the reproduction. It turns out that this is a bug in Scala.js so I've raised scala-js/scala-js#4545

Here's a workaround for now:

-                s.intsTheseDays
+                s.intsTheseDays: Double