Skip to content

Conversation

shihaohong
Copy link
Contributor

@shihaohong shihaohong commented Dec 29, 2020

Description

Fixes #72453.

However, I'm running into trouble writing the test. The expect statements catch the new assert I added, but there is another unrelated assert that throws somehow after the test function body is done executing, and I'm not sure how to catch it or stop it from happening. I've tried adding and awaiting widget pump, pumpAndSettle, even pumpWidget at the end of the test function, but I'm not sure what's going on and at this point I'm just trying random things to make the assert go away:

00:05 +29: Helpful assert thrown all routes in onGenerateInitialRoutes are not restorable                                        
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown attaching to the render tree:
'package:flutter/src/widgets/framework.dart': Failed assertion: line 5150 pos 14:
'_dependents.isEmpty': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

When the exception was thrown, this was the stack:
#2      InheritedElement.debugDeactivated.<anonymous closure> (package:flutter/src/widgets/framework.dart:5150:14)
#3      InheritedElement.debugDeactivated (package:flutter/src/widgets/framework.dart:5152:6)
#4      _InactiveElements._deactivateRecursively.<anonymous closure> (package:flutter/src/widgets/framework.dart:2044:15)
#5      _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:2046:6)
#6      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4735:14)
#7      _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:2042:13)
#8      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4735:14)
#9      _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:2042:13)
#10     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4735:14)
#11     _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:2042:13)
#12     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4735:14)
#13     _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:2042:13)
#14     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4735:14)
#15     _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:2042:13)
#16     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4735:14)
#17     _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:2042:13)
#18     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4735:14)
#19     _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:2042:13)
#20     _InactiveElements.add (package:flutter/src/widgets/framework.dart:2054:7)
#21     Element.deactivateChild (package:flutter/src/widgets/framework.dart:3657:30)
#22     Element.updateChild (package:flutter/src/widgets/framework.dart:3381:9)
#23     RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1208:16)
#24     RenderObjectToWidgetElement.update (package:flutter/src/widgets/binding.dart:1186:5)
#25     RenderObjectToWidgetElement.performRebuild (package:flutter/src/widgets/binding.dart:1200:7)
#26     Element.rebuild (package:flutter/src/widgets/framework.dart:4375:5)
#27     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2774:33)
#28     AutomatedTestWidgetsFlutterBinding.drawFrame (package:flutter_test/src/binding.dart:1110:19)
#29     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:320:5)
#30     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144:15)
#31     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1082:9)
#32     AutomatedTestWidgetsFlutterBinding.scheduleWarmUpFrame (package:flutter_test/src/binding.dart:1056:5)
#33     runApp (package:flutter/src/widgets/binding.dart:1049:7)
#34     TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:804:7)
<asynchronous suspension>
(elided 2 frames from class _AssertionError)
════════════════════════════════════════════════════════════════════════════════════════════════════
00:05 +29 -1: Helpful assert thrown all routes in onGenerateInitialRoutes are not restorable [E]                                 
  Test failed. See exception logs above.
  The test description was: Helpful assert thrown all routes in onGenerateInitialRoutes are not restorable

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Dec 29, 2020
@google-cla google-cla bot added the cla: yes label Dec 29, 2020
@shihaohong shihaohong changed the title Navigator assert on non restorable routes Navigator assert on non restorable routes returned by onGenerateInitialRoutes Dec 29, 2020
@shihaohong shihaohong added the a: state restoration RestorationManager and related APIs label Dec 29, 2020
@chunhtai
Copy link
Contributor

This is due to the tree is left half broken and the test fail to tear it down. I remember I ran into this issue before, and the way i do it is to make sure the tree is restored before the test ends

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM, modulo nits and failing test

assert(
_history.isNotEmpty,
'All routes returned by onGenerateInitialRoutes are not restorable. '
'Please make sure that all routes returned in onGenerateInitialRoutes '
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'Please make sure that all routes returned in onGenerateInitialRoutes '
'Please make sure that all routes returned from the onGenerateInitialRoutes '

_history.isNotEmpty,
'All routes returned by onGenerateInitialRoutes are not restorable. '
'Please make sure that all routes returned in onGenerateInitialRoutes '
'have their RouteSettings defined with a name that is defined in the '
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'have their RouteSettings defined with a name that is defined in the '
'have their RouteSettings defined with names that are defined in the '

@fluttergithubbot fluttergithubbot merged commit 0b6af5a into flutter:master Dec 31, 2020
@shihaohong shihaohong deleted the error-message branch January 6, 2021 04:11
@shihaohong shihaohong changed the title Navigator assert on non restorable routes returned by onGenerateInitialRoutes [State Restoration] Navigator assert on non restorable routes returned by onGenerateInitialRoutes Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: state restoration RestorationManager 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.

State Restoration: Provide better error message if initial routes produced by onGenerateInitialRoutes are not restorable
3 participants