-
Notifications
You must be signed in to change notification settings - Fork 222
Fix reloading after sections updates #140
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 reloading after sections updates #140
Conversation
@bryankeller
bryankeller
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the change! It would be helpful if a repro case for this bug was provided. Would this be easy to provide?
One other question: would it be simpler to just not update the layout metrics for existing sections if we're recreating them from scratch anyways? Maybe the change is even simpler:
// Update layout metrics if necessary if prepareActions.contains(.updateLayoutMetrics) { ...
becomes
// Update layout metrics if necessary if !prepareActions.contains(.recreateSectionModels), prepareActions.contains(.updateLayoutMetrics) { ...
Let me know if this works. And if you can provide a repro-case, that would be really helpful so I can better-understand what application behavior triggers this.
Uh oh!
There was an error while loading. Please reload this page.
Details
The CollectionView reload is triggered by this func from the MagazineLayout Library :
imageIf we follow that call it comes from the override public func prepare() here :
image (2)The prepareActions is a bit field, and you check for updateLayoutMetrics (which triggers the updates) and just bellow that highlighted line of code on the screenshot the following condition checks for recreateSectionModels which are both set to true in our situation.
The fix
Screenshot 2025年08月22日 at 2 06 23 pmThe recreateSectionModels code should be called before updateLayoutMetrics if recreateSectionModels is set to true because there is no need to update the sections if we are going to recreate them anyway right after the update.
Related Issue
We have a very old crash that is occurring on our main iPad app.
The crash happens following these steps :
-> CRASH
It crashes because there is more sections on the Home Page when the user is logged (34 sections) in compared to when the user is logged out (28 sections), some sections are based on the user's preferences and his content, like recommended, suggested...).
The current code implementation tries to update the existing sections and an out of bounds crash will occur because the number of sections logged out are inferior and it will attempt to update a section that just doesn't exist.
Motivation and Context
The current behaviour is the following :
This fix just swap the 2 steps, check for recreation first and then for updates.
How Has This Been Tested
The reproducibility of this crash was 100% in our situation (following steps detailed up here).
Tested on :
Types of changes
Checklist