Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ class BuildOutputFragment : NonEditableEditorFragment() {
}

override fun clearOutput() {
buildOutputViewModel.clear()
// This fragment uses `activityViewModels()`, which relies on the fragment being attached.
// `clearOutput()` can be triggered from build/service callbacks even after the fragment
// has been detached, so we must guard before touching the activity-scoped ViewModel.
if (isAdded && !isDetached) {
buildOutputViewModel.clear()
}
Comment on lines +97 to +99
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid double-clearing shared build-output state here.

EditorBottomSheet already clears BuildOutputViewModel before calling fragment.clearOutput(). Clearing again in this fragment can race with fresh append() activity and wipe newly cached output/session state.

Suggested fix
 override fun clearOutput() {
-		// This fragment uses `activityViewModels()`, which relies on the fragment being attached.
-		// `clearOutput()` can be triggered from build/service callbacks even after the fragment
-		// has been detached, so we must guard before touching the activity-scoped ViewModel.
-		if (isAdded && !isDetached) {
-			buildOutputViewModel.clear()
-		}
+		// Shared build-output state is cleared by the caller-side ViewModel owner
+		// (e.g., EditorBottomSheet). Keep fragment clear local to UI/editor state.
 		super.clearOutput()
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (isAdded && !isDetached) {
buildOutputViewModel.clear()
}
override fun clearOutput() {
// Shared build-output state is cleared by the caller-side ViewModel owner
// (e.g., EditorBottomSheet). Keep fragment clear local to UI/editor state.
super.clearOutput()
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@app/src/main/java/com/itsaky/androidide/fragments/output/BuildOutputFragment.kt`
around lines 97 - 99, Remove the redundant call to buildOutputViewModel.clear()
in BuildOutputFragment to avoid racing with fresh append() activity from other
components (EditorBottomSheet already clears the shared BuildOutputViewModel and
calls fragment.clearOutput()); specifically, delete or disable the
buildOutputViewModel.clear() invocation inside the isAdded && !isDetached check
so the fragment no longer double-clears the shared state and conflicts with
EditorBottomSheet's clear logic.

super.clearOutput()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ interface ShareableOutputFragment {
/** Get the name of the file to which the output will be written. */
fun getShareableFilename(): String

/** Clear the output of this fragment. */
/**
* Clear the output of this fragment.
*
* Note: Callers may invoke this while the fragment is detached (for example, from a
* build/service callback). Implementations that use activity-scoped ViewModels must
* guard against `!isAdded || isDetached` before touching them.
*/
fun clearOutput()
}
11 changes: 10 additions & 1 deletion app/src/main/java/com/itsaky/androidide/ui/EditorBottomSheet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,16 @@ constructor(
suppressedGradleWarnings.any { msg.contains(it) }

fun clearBuildOutput() {
pagerAdapter.buildOutputFragment?.clearOutput()
// Always clear the persistent build output state via the bottom sheet's
// activity-scoped ViewModel.
buildOutputViewModel.clear()

// `clearOutput()` on the fragment may touch additional UI state, so only call it when
// the fragment is currently attached to an activity.
val fragment = pagerAdapter.buildOutputFragment
if (fragment != null && fragment.isAdded && !fragment.isDetached) {
fragment.clearOutput()
}
}

fun handleDiagnosticsResultVisibility(errorVisible: Boolean) {
Expand Down
Loading