Skip to content

Fixes Router transaction to respect operation order #149763

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

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

chunhtai
Copy link
Contributor

@chunhtai chunhtai commented Jun 5, 2024

fixes #142393

The issue is that if routerdelegate mutate its currentConfiguration outside of Router's workflow, the change will be propagate back to routeinformationprovider at the end of the frame.
However if another things trigger router's dependencies change within the same frame. The dependencies will trigger a reparse of the current route which would end up override the currentConfiguration in routerDelegate.

This change introduce a transaction system that each operation will be add to the end of the transaction future so everything will be execute inorder

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: routes Navigator, Router, and related APIs. labels Jun 5, 2024
@chunhtai chunhtai requested a review from goderbauer June 5, 2024 20:28
@goderbauer
Copy link
Member

Looks like this is breaking something in go_router (via Google testing)?

@chunhtai
Copy link
Contributor Author

chunhtai commented Jun 5, 2024

yes I am surprised we don't have ci to run against package? anyway I will look into it

final _RestorableRouteInformation _routeInformation = _RestorableRouteInformation();
late bool _routeParsePending;

// A token and transaction system to make sure that tasks added to the
// transactions are executed FIFO and will abort when token changes.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe:

Suggested change
// transactions are executed FIFO and will abort when token changes.
// transaction are executed in FIFO order and will abort when the token changes.

// A token and transaction system to make sure that tasks added to the
// transactions are executed FIFO and will abort when token changes.
//
// If the task also perform async operation, it needs to check whether the
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// If the task also perform async operation, it needs to check whether the
// If the task also performs async operations, it needs to check after any async gaps whether the

// currentToken is still the same as _currentTransactionToken.
Object _currentTransactionToken = Object();
late Future<Object> _currentTransaction = SynchronousFuture<Object>(_currentTransactionToken);
void _addToCurrentTransaction(_AsyncCallback task) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you document when the future returned by _AsyncCallback is suppose to complete?

Comment on lines 606 to 611
_currentTransaction = _currentTransaction.then<Object>((Object token) {
if (token != _currentTransactionToken) {
return SynchronousFuture<Object>(token);
}
return task(token).then<Object>((void data) => token);
});
Copy link
Member

Choose a reason for hiding this comment

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

Is it necessary to pass the tokens through the futures or could this be simplified to something like:

    final Object transactionToken = _currentTransactionToken;
    _currentTransaction = _currentTransaction.then<void>((void _) {
      if (transactionToken != _currentTransactionToken) {
        return SynchronousFuture<void>(null);
      }
      return task(transactionToken);
    });

(Duration timestamp) => _reportRouteInformation(timestamp, completer),
debugLabel: 'Router.reportRouteInfo',
);
return completer.future;
Copy link
Member

Choose a reason for hiding this comment

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

So, the transaction is on hold until the post frame callback? No other task can execute until then?

final Completer<bool> backButtonCompleter = Completer<bool>();
// Completer to pass result form widget.routerDelegate.popRoute between two
// tasks
_addToCurrentTransaction((Object currentToken) {
Copy link
Member

Choose a reason for hiding this comment

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

So, previously we would respond to the back button right away, now it may be delayed after some other tasks. Is that gonna create a lagging user experience?

@chunhtai chunhtai requested a review from goderbauer June 5, 2024 22:33
@chunhtai
Copy link
Contributor Author

chunhtai commented Jun 5, 2024

lol, should have discussed with you sooner, much simpler now

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

Nice!

LGTM

@chunhtai chunhtai added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 5, 2024
@auto-submit auto-submit bot merged commit c1064da into flutter:master Jun 5, 2024
72 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2024
@polina-c polina-c mentioned this pull request Jun 6, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jun 6, 2024
flutter/flutter@27e0656...4608a89

2024-06-06 [email protected] Fix InputDecorator suffixIcon color when in error and hovered (flutter/flutter#149643)
2024-06-06 [email protected] Roll Flutter Engine from 32c3b9b7cbe1 to 92d0cd9370f7 (1 revision) (flutter/flutter#149789)
2024-06-06 [email protected] Roll Flutter Engine from 0edca2e9d3d2 to 32c3b9b7cbe1 (2 revisions) (flutter/flutter#149786)
2024-06-06 [email protected] Roll Flutter Engine from f51e0ad3abbe to 0edca2e9d3d2 (8 revisions) (flutter/flutter#149785)
2024-06-06 [email protected] Roll Flutter Engine from f37733035060 to f51e0ad3abbe (3 revisions) (flutter/flutter#149778)
2024-06-05 [email protected] Remove abi key from local golden file testing (flutter/flutter#149696)
2024-06-05 [email protected] Fixes Router transaction to respect operation order (flutter/flutter#149763)
2024-06-05 [email protected] Send q once (flutter/flutter#149767)
2024-06-05 [email protected] Marks Mac_ios rrect_blur_perf_ios__timeline_summary to be unflaky (flutter/flutter#149729)
2024-06-05 [email protected] Add `contrastLevel` parameter to `ColorScheme.fromSeed` (flutter/flutter#149705)
2024-06-05 [email protected] Roll Flutter Engine from 11a32d43e3f6 to f37733035060 (11 revisions) (flutter/flutter#149770)
2024-06-05 [email protected] Remove unused code from an older test artifact. (flutter/flutter#149746)
2024-06-05 [email protected] Create CarouselView widget - Part 1 (flutter/flutter#148094)
2024-06-05 [email protected] [flutter_tools] Remove additional listener on VM service that simply logged incoming messages (flutter/flutter#149756)
2024-06-05 [email protected] Fix signature for TokenTemplate.updateFile (flutter/flutter#149673)
2024-06-05 [email protected] Remove temporary LayoutBuilder migration flag, defer `markNeedsLayout` (flutter/flutter#149637)
2024-06-05 [email protected] Revert "make output of flutter run web tests verbose (#149694)" (flutter/flutter#149766)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App f: routes Navigator, Router, and related APIs. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[go_router] Cannot go to the target page when using redirect
2 participants