Skip to content

Commit 66b795c

Browse files
fix(mobile): Android terminal feeds output after the prop batch's grid lands
Expo applies a batch's props in ReadableMap iteration order, so initialBuffer could be parsed at the previous grid before the same batch's sharedGrid resized the terminal. Defer the feed to OnViewDidUpdateProps and keep creation/recreation from feeding early while a buffer is pending, matching the iOS surface. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 792b345 commit 66b795c

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalModule.kt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class T3TerminalModule : Module() {
6767
}
6868
Events("onInput", "onResize", "onCapture")
6969

70+
OnViewDidUpdateProps { view: T3TerminalView ->
71+
view.applyPendingBuffer()
72+
}
73+
7074
OnViewDestroys { view: T3TerminalView ->
7175
view.cleanup()
7276
}

‎apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalView.kt‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,16 @@ class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(contex
7575
recreateTerminal()
7676
}
7777

78+
// Expo sets a batch's props in no fixed order, so the buffer waits for the whole batch:
79+
// output fed before the same batch's sharedGrid lands would be drawn, and clipped, at the
80+
// previous grid.
7881
var initialBuffer: String = ""
7982
set(value) {
8083
if (field == value) return
8184
field = value
82-
feedPendingBuffer()
85+
hasPendingBuffer = true
8386
}
87+
private var hasPendingBuffer = false
8488

8589
var fontSize: Float = 10f
8690
set(value) {
@@ -369,7 +373,7 @@ class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(contex
369373
)
370374
}
371375
emitResponse(response)
372-
feedPendingBuffer()
376+
if (!hasPendingBuffer) feedPendingBuffer()
373377
renderSnapshot()
374378
}
375379

@@ -393,7 +397,7 @@ class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(contex
393397
if (terminalHandle == 0L) return
394398
destroyTerminal()
395399
createTerminal()
396-
feedPendingBuffer()
400+
if (!hasPendingBuffer) feedPendingBuffer()
397401
renderSnapshot()
398402
}
399403

@@ -405,6 +409,12 @@ class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(contex
405409
terminalCanvas.resetSelectionState()
406410
}
407411

412+
fun applyPendingBuffer() {
413+
if (!hasPendingBuffer) return
414+
hasPendingBuffer = false
415+
feedPendingBuffer()
416+
}
417+
408418
private fun feedPendingBuffer() {
409419
if (terminalHandle == 0L || initialBuffer == fedBuffer) return
410420
if (!initialBuffer.startsWith(fedBuffer)) {

0 commit comments

Comments
 (0)