Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible crash when having identical subspaces in multiple root spaces #4693

Merged
merged 2 commits into from
Dec 13, 2021

Conversation

SpiritCroc
Copy link
Contributor

@SpiritCroc SpiritCroc commented Dec 12, 2021

When you have two root spaces with the same space as subspace, and you expand both root spaces, you end up with two times the same id in the list. This has two problems:

  • The expand animation is slightly broken, if you expand the second root space first and then the first one
  • If you select one of these items with same id, the app crashes:
    java.lang.IllegalStateException: Two different ViewHolders have the same stable ID. Stable IDs in your adapter MUST BE unique and SHOULD NOT change.

As solution, just prefix the epoxy item ids with the parent spaces.

Signed-off-by: Tobias Büttner [email protected]

Pull Request Checklist

When you have two root spaces with the same space as subspace, and you expand both root spaces, you end up with two times the same id in the list. This has two problems:

- The expand animation is slightly broken, if you expand the second root space first and then the first one
- If you select one of these items with same id, the app crashes:
    java.lang.IllegalStateException: Two different ViewHolders have the same stable ID. Stable IDs in your adapter MUST BE unique and SHOULD NOT change.

As solution, just prefix the epoxy item ids with the parent spaces.
@@ -181,7 +181,8 @@ class SpaceSummaryController @Inject constructor(
}
}

private fun buildSubSpace(summaries: List<RoomSummary>?,
private fun buildSubSpace(idPrefix: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit pick - it could help make this a little easier to understand if we highlight the parent/child space relationship
what do you think?

fun buildSubSpace(parentId: String) {
  val id = "$parent:$child"

  spaceSummaryItem {
    id(id)
  }

  subSpaces.forEach { child ->
    buildSubSpace(parent = id)
  }
}

Copy link
Contributor

@ouchadam ouchadam left a comment

Choose a reason for hiding this comment

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

great find! 👍

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

Thanks!

@bmarty bmarty merged commit 3719551 into element-hq:develop Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants