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: take preload into account when freezing children #2566

Merged
merged 4 commits into from
Dec 12, 2024

Conversation

WoLewicki
Copy link
Member

Description

Fixed #2557. We have to take preloaded screens into account when freezing screens. Till now, the assumption was that the newest screens are the ones rendered, right now top children can be the preloaded ones, so we have to filter them from calculating the size of frozen screens. We could also think of freezing the preloaded screens, wdyt about it @satya164 ?

Changes

Test code and steps to reproduce

TestFreeze now includes preloading of screens, even more than 1 to see that the current one still gets the updates.

Checklist

  • Included code example that can be used to test this change

@satya164
Copy link
Collaborator

We could also think of freezing the preloaded screens

I think we need to leave them unfrozen so that effects etc. can run on that screen to load everything required.

@WoLewicki
Copy link
Member Author

I think we need to leave them unfrozen so that effects etc. can run on that screen to load everything required.

I mean there is one render before the screen is frozen, but it might not be enough so it makes sense.

@hirbod
Copy link
Contributor

hirbod commented Dec 10, 2024

Freezing usually doesn’t affect effects, right? It only stops re-rendering the UI, no? I think preloaded screens can be frozen—it’s just their UI not being updated. But I think that’s kind of against the whole purpose of preloading or pre-rendering a screen. So, it makes sense not to freeze preloaded screens.

@WoLewicki
Copy link
Member Author

We could also add prop freezeOnPreload or something like that 🤷‍♂️ I'm okay with doing the logic on the react-navigation side and just pass a prop to children deciding if the screen should be frozen or not. Or even do the freezing on the navigation side too to keep it always in sync?

@satya164
Copy link
Collaborator

I'm okay with doing the logic on the react-navigation side and just pass a prop to children deciding if the screen should be frozen or not. Or even do the freezing on the navigation side too to keep it always in sync

Either is fine but I think the second one will be breaking, so for now I think it maybe good to add a new prop like freeze and whether a screen would be frozen or not can be decided by react navigation.

src/components/Screen.tsx Outdated Show resolved Hide resolved
satya164 added a commit to react-navigation/react-navigation that referenced this pull request Dec 12, 2024
**Motivation**

PR connected to
software-mansion/react-native-screens#2566
moving the freezing logic to `react-navigation` since we have control
over `preloaded` screens here.

**Test plan**

`TestFreeze` in `RNScreens` repo.

---------

Co-authored-by: Satyajit Sahoo <[email protected]>
Copy link
Member

@kkafar kkafar left a comment

Choose a reason for hiding this comment

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

Both https://github.com/react-navigation/react-navigation/pull/12332/files and this one look reasonable.

Only thing that missing is whether we want to document somewhere that we don't freeze preloaded screens or leave it "unstable". Same for fabric behaviour (top most two screens not frozen) we introduced a while back.

@WoLewicki
Copy link
Member Author

Yeah, it would be nice to inform people that behavior differs on old/new arch. As for preloaded screens, I would add a prop on e.g. navigator to decide if we should freeze preloaded screens too, but it is on the side of react-navigation. cc @satya164 for follow-ups on this one.

@WoLewicki WoLewicki merged commit 6e37c7e into main Dec 12, 2024
3 checks passed
@WoLewicki WoLewicki deleted the @wolewicki/check-preload-for-freeze branch December 12, 2024 10:24
@satya164
Copy link
Collaborator

@WoLewicki PRs to docs is welcome :)

@hirbod
Copy link
Contributor

hirbod commented Dec 12, 2024

I started a discussion about re-thinking react-freeze a little bit. They are definitely some flaws/inconsistencies that should be tackled in the future. I opened the discussion over at react-navigation, I can move it to RNS if the place is wrong

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.

navigation.preload() with enableFreeze breaks app, stopping rendering
4 participants