Skip to content

Fix section moves#134

Merged
bryankeller merged 1 commit intomasterfrom
bk/fix-section-moves
Apr 11, 2025
Merged

Fix section moves#134
bryankeller merged 1 commit intomasterfrom
bk/fix-section-moves

Conversation

@bryankeller
Copy link
Contributor

@bryankeller bryankeller commented Apr 11, 2025

Details

This fixes section moves causing incorrect layouts. This has shockingly been broken since MagazineLayout was created in 2017/18 💀

When a section is moved, UICollectionView also generates individual item move updates to go along with the section move. Those eventually turn into some item insertions. If we don't first clear out all existing items in the moved section, then the item insertions will insert all existing items back into the same section, effectively doubling the number of items in the section.

This bug thankfully doesn't cause a crash, but it does cause a section to take up more space than it should since it has more items in it. Keep in mind that these are layout models, not data source models, which explains why this doesn't actually cause a data-source-related crash.

AFAIK, this bug was never reported, and we never ran into it at Airbnb - turns out we don't move sections around very often!

Related Issue

N/A

Motivation and Context

Bug fix.

How Has This Been Tested

Example app, unit tests.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@bryankeller bryankeller requested a review from brynbodayle April 11, 2025 23:09
@bryankeller bryankeller added the bug Something isn't working label Apr 11, 2025
@bryankeller bryankeller merged commit 3efa492 into master Apr 11, 2025
1 check passed
@bryankeller bryankeller deleted the bk/fix-section-moves branch April 11, 2025 23:42
@bryankeller bryankeller mentioned this pull request Oct 16, 2025
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants