Hello all, I have encountered a problem using IR (...
# javascript
a
Hello all, I have encountered a problem using IR (1.4.20) here.
browserDevelopmentRun
successfully runs while
browserProductionRun
fails. Is this a bug?
a
As far as I remember, it is the problem with DCE. You need to mark all components with JsExport and make all props and state with external interface. There is a commen in a youtrack issue about that.
r
a
Thanks @Robert Jaros
r
I've been struggling with this yesterday, too.
had to implement my own version of
RComponent
class
a
Thank you so much for this.
@Robert Jaros may you please share your implementation of
RComponent
?
r
I can, but the class is simplified and specific to KVision internals. Generally it's just about annotating it with
@JsExport
Copy code
@OptIn(ExperimentalJsExport::class)
@JsExport
internal abstract class KVRComponent<P : ReactComponentProps, S : RState> : Component<P, S>() {
    init {
        state = jsObject { init(props) }
    }

    open fun S.init(props: P) {}

    @JsName("RBuilder_children")
    fun RBuilder.children() {
        props.children()
    }

    fun <T> RBuilder.children(value: T) {
        props.children(value)
    }

    @JsName("RBuilder_render")
    fun RBuilder.render() {
        props.renderFunction(this) {
            setState {
            }
        }
    }

    override fun render() = buildElements { render() }
}
a
So just adding this, then I don't need to add
@JsExport
to my components implementing
KVRComponent
?
r
I had to add this to my component as well.
a
Thanks @Robert Jaros