JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.97k stars 1.16k forks source link

Web: Dom element rendered by compose then moved by external lib outside compose hierarchy make compose crash #1085

Closed ylemoigne closed 1 day ago

ylemoigne commented 3 years ago

It's a very edge usecase I think, I post it for info/reference but understand that it's priority will be somewhere between unsupported and maybe in version 12...

I use compose with UIKit ( https://github.com/uikit/uikit ). When using UIKit modal feature ( https://getuikit.com/docs/modal ), the modal display correctly and close correctly. But at next highter hierarchy recomposition it crash with an NPE.

name: "NullPointerException"
​
stack: "captureStack@webpack-internal:///./kotlin/YafullStack-NoteApp-app-frontend.js:19115:25
NullPointerException_init_$Create$@webpack-internal:///./kotlin/YafullStack-NoteApp-app-frontend.js:21261:17
THROW_NPE@webpack-internal:///./kotlin/YafullStack-NoteApp-app-frontend.js:19201:11
ensureNotNull@webpack-internal:///./kotlin/YafullStack-NoteApp-app-frontend.js:19194:7
DomNodeWrapper.prototype.remove_rvwcgf_k$@webpack-internal:///./kotlin/YafullStack-NoteApp-app-frontend.js:73866:25
DomApplier.prototype.remove_rvwcgf_k$@webpack-internal:///./kotlin/YafullStack-NoteApp-app-frontend.js:73911:31

What happen, if that the hierarchy at first rendering is something like

Body
  - Compose RootEl
    - AComponent
      - Modal Toggle Something
      - ModalContent

When the modal is first displayed, UIKit impl move the modal under the body :

Body
  - Compose RootEl
    - AComponent
      - Modal Toggle Something
 - ModalContent

When the modal is "closed" (uikit just hide it), it stay under the body element.

Then a rendering happen, and the "forced" non null here https://github.com/JetBrains/compose-jb/blob/d2d4971f282ce02c6647f852b197651424307a27/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/DomApplier.kt#L74 make the crash.

okushnikov commented 4 weeks ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.