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

[SuperEditor] Add test to demonstrate that changing layer builders does not re-layout #2388

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

angelosilvestre
Copy link
Collaborator

[SuperEditor] Add test to demonstrate that changing layer builders does not re-layout

Changing SuperEditor overlay builders doesn't trigger a re-layout. An overlay can change, for example, to switch the caret color depending on the theme.

This was discussed in #2042

This PR adds tests to demonstrate that issue. The first test, which only switches the theme, fails. The second test, that types a character after switching themes, passes.

MaterialApp(
home: Scaffold(
body: ValueListenableBuilder(
valueListenable: brightnessNotifier,
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at this widget tree, I'm a little confused about the build behavior.

Your description of the problem is that the overlay builders don't rebuild when the brightness changes.

I'm reading through this tree. I see the ValueListenableBuilder, which rebuilds whenever the brightness changes. When the ValueListenableBuilder rebuilds, it should construct a new SuperEditor instance, which then creates a new DefaultCaretOverlayBuilder. If we're rebuilding the ValueListenableBuilder, and rebuilding the SuperEditor, why isn't the DefaultCaretOverlayBuilder being built?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because none of the document nodes changed its content. Thus, we are not running another layout phase. We are only repainting the document components, without running a layout phase ContentLayers won't build the overlayers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you phrase that statement in terms of the chain of events that I described? What did I get wrong in that series of events? It's not clear what "none of the document nodes changed" has to do with my comment. If we're rebuilding SuperEditor then why isn't SuperEditor running build on its internal ContentLayers? Where are those two builds getting disconnected, such that SuperEditor runs widget build, but ContentLayers doesn't?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the sequence of methods being called:

-> INITIAL BUILD
ValueListenableBuilder -> build
SuperEditor -> build
DocumentScaffold -> build
RenderContentLayers -> performLayout
ContentLayersElement -> buildLayers
RenderContentLayers -> performLayout
ContentLayersElement -> buildLayers

-> VALUE NOTIFIER CHANGED 
ValueListenableBuilder -> build
SuperEditor -> build
DocumentScaffold -> build
ContentLayersElement -> update

The critical thing for us is that RenderContentLayers.performLayout is not called. It seems the subtree isn't considered dirty, so the layout does not run again.

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.

2 participants