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

Clarify documentation about when Flutter stops rebuilding #38740

Closed
derolf opened this issue Aug 17, 2019 · 2 comments · Fixed by flutter/website#8398 or #122787
Closed

Clarify documentation about when Flutter stops rebuilding #38740

derolf opened this issue Aug 17, 2019 · 2 comments · Fixed by flutter/website#8398 or #122787
Assignees
Labels
d: api docs Issues with https://api.flutter.dev/ framework flutter/packages/flutter repository. See also f: labels. P2 Important issues not at the top of the work list r: fixed Issue is closed as already fixed in a newer version

Comments

@derolf
Copy link

derolf commented Aug 17, 2019

In the best-practies it reads:

The traversal to rebuild all descendents stops when the same instance of the child widget as the previous frame is re-encountered.

People confuse "same" with "equal" vs "identical". So, the question raises whether Flutter is using the operator== or the identical function to determine when to stop rebuilding. Here is the code from framework.dart:

  if (child.widget == newWidget) {
    if (child.slot != newSlot)
      updateSlotForChild(child, newSlot);
    return child;
  }

Obviously, "same instance" in the docs is highly misleading and it should rather read "equal instances". Hence, two non-identical widgets with the same runtime-type and key that are equal with respect to == will stop rebuilding. That's an important aspect for performance optimisations.

For sure, the operator== defaults to identical in Dart, hence overriding operator== for a Widget is required to let the optimisation kick in.

I think it would make sense to clarify that in the docs. (Replace "same" with "equal" and elaborate on the fact.)

Link to Stackoverflow:

@BondarenkoStas BondarenkoStas added the d: api docs Issues with https://api.flutter.dev/ label Sep 5, 2019
@kf6gpe kf6gpe added the framework flutter/packages/flutter repository. See also f: labels. label Jan 27, 2020
@whesse
Copy link
Contributor

whesse commented Sep 10, 2020

Another place in the documentation where this is unclear is in the documentation of the StatelessWidget class.

It says
The build method of a stateless widget is typically only called in three situations: the first time the widget is inserted in the tree, when the widget's parent changes its configuration, and when an InheritedWidget it depends on changes.

It is unclear what "configuration" means here, it seems to be the arguments to the widget's constructor.

It is unclear whether the "first time the widget is inserted in the tree" means the first time a widget of this type is inserted at this location in the tree, or the first time this widget instance is inserted in the tree. Neither seems to be correct.

When the parent rebuilds, and an identical, an equal, or a constant (identical) widget instance appears here, the build method won't be (necessarily) called. If the parent build method introduces a new instance of the same widget, even with the same constructor arguments, its build method will be called unless operator== says it is equal to the previous instance.

@goderbauer goderbauer added the P2 Important issues not at the top of the work list label Jan 18, 2023
Hixie added a commit to flutter/website that referenced this issue Mar 16, 2023
@Hixie Hixie self-assigned this Mar 16, 2023
@Hixie Hixie added the waiting for PR to land (fixed) A fix is in flight label Mar 16, 2023
Hixie added a commit to flutter/website that referenced this issue Mar 16, 2023
Hixie added a commit to Hixie/flutter that referenced this issue Mar 17, 2023
@danagbemava-nc danagbemava-nc added r: fixed Issue is closed as already fixed in a newer version and removed waiting for PR to land (fixed) A fix is in flight labels Mar 23, 2023
@github-actions
Copy link

github-actions bot commented Apr 6, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
d: api docs Issues with https://api.flutter.dev/ framework flutter/packages/flutter repository. See also f: labels. P2 Important issues not at the top of the work list r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
8 participants