ReviewOS

also looking at this

craft-native/craft

fix(native): preserve workspace sources and native overlay lifecycle

#384
Merged chris wants to merge codex/windows-zig-cache-diagnostics into main
20 files +500 -227

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

packages/android/src/retained-identity.test.tsmodified+13-3
Changes to packages/android/src/retained-identity.test.ts
@@ -77,10 +77,12 @@ fun main() {
7777
7878test('preserves modal viewport promotion and ordering across targeted reconciliation', async () => {
7979 const template = await Bun.file(new URL('../templates/MainActivityNative.kt.template', import.meta.url)).text()
80 const promote = template.match(/ private fun promoteModalOverlays\(screen: Screen, controls: Collection<View>\) \{[\s\S]*?\n \}/)?.[0]
80 const promote = template.match(/ private fun promoteModalOverlays\(screen: Screen\) \{[\s\S]*?\n \}/)?.[0]
8181 const targeted = template.match(/ private fun applyTargetedUpdates\(screen: Screen, ids: List<String>\): Boolean \{[\s\S]*?\n \}/)?.[0]
8282 if (!promote || !targeted) throw new Error('Native modal reconciliation implementation is missing')
8383 await runKotlinFixture(`
84import kotlin.math.min
85
8486open class View {
8587 var parent: ViewGroup? = null
8688 fun bringToFront() { val group = parent ?: return; group.children.remove(this); group.children.add(this) }
@@ -88,6 +90,8 @@ open class View {
8890open class ViewGroup : View() {
8991 val children = mutableListOf<View>()
9092 val childStyles = mutableMapOf<View, JSONObject>()
93 val childCount: Int get() = children.size
94 fun getChildAt(index: Int): View = children[index]
9195 fun removeView(view: View) { children.remove(view); childStyles.remove(view); view.parent = null }
9296 fun setChildStyle(view: View, style: JSONObject, density: Float) { childStyles[view] = style }
9397 fun addView(view: View) { view.parent?.removeView(view); children.add(view); view.parent = this }
@@ -95,6 +99,7 @@ open class ViewGroup : View() {
9599class CraftNativeModalView : ViewGroup() {
96100 val content = ViewGroup().also(::addView)
97101 var viewportStyle = JSONObject("popup-frame")
102 var declarationPath = ""
98103}
99104class DisplayMetrics { val density = 1f }
100105class Resources { val displayMetrics = DisplayMetrics() }
@@ -111,6 +116,7 @@ class Screen {
111116 val nodePaths = mutableMapOf<String, String>()
112117 val protocolIds = mutableMapOf<View, String>()
113118 val lastLayoutBounds = mutableMapOf<View, String>()
119 val modalVisibility = mutableMapOf<View, Boolean>()
114120 val mutations = MutationDocument(mapOf("parent" to "root", "nested" to "parent", "standalone" to "root"))
115121 var layoutEvents = 0
116122}
@@ -134,12 +140,16 @@ fun main() {
134140 parent.content.addView(nested)
135141 root.addView(standalone)
136142 for (modal in listOf(parent, nested, standalone)) screen.view.setChildStyle(modal, modal.viewportStyle, 1f)
143 parent.declarationPath = "0"
144 nested.declarationPath = "0.0"
145 standalone.declarationPath = "1"
137146 for ((id, view) in listOf("root" to root, "nested" to nested, "parent" to parent, "standalone" to standalone)) {
138147 screen.nodeViews[id] = view
139148 screen.nodePaths[id] = id
140149 screen.protocolIds[view] = id
141150 screen.controls[id] = view
142151 screen.controls["id:" + id] = view
152 if (view is CraftNativeModalView) screen.modalVisibility[view] = true
143153 }
144154 fun verify() {
145155 check(parent.parent === screen.view && nested.parent === screen.view && standalone.parent === screen.view) { "An overlay escaped its viewport" }
@@ -148,7 +158,7 @@ fun main() {
148158 check(children.indexOf(parent) < children.indexOf(nested)) { "The parent scrim covered its nested popup" }
149159 check(children.indexOf(nested) < children.indexOf(standalone)) { "Sibling overlay order changed" }
150160 }
151 promoteModalOverlays(screen, screen.controls.values)
161 promoteModalOverlays(screen)
152162 verify()
153163 check(applyTargetedUpdates(screen, listOf("parent")))
154164 verify()
@@ -159,7 +169,7 @@ fun main() {
159169 parent.content.addView(nested)
160170 root.addView(standalone)
161171 screen.protocolIds.clear()
162 promoteModalOverlays(screen, screen.controls.values)
172 promoteModalOverlays(screen)
163173 verify()
164174 println("PASS modal viewport, nested scrim ordering, sibling ordering, targeted updates and legacy renders")
165175}