Unnecessary widget rebuilds when navigating between pages in Riverpod 3.0 #4665
-
DescriptionAfter migrating from Riverpod 2.x to 3.0, I'm experiencing excessive widget rebuilds when navigating between pages. Every time I navigate to a new page, all previous pages in the navigation stack that extend This behavior seems related to the new provider pause/resume mechanism in 3.0. Expected Behavior (Riverpod 2.x)
Current Behavior (Riverpod 3.0)
This causes 3+ unnecessary rebuilds in my application just for simple navigation. Exampleclass Page1 extends ConsumerWidget {
const Page1({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
print("[Widget Build] Page1");
return Scaffold(
appBar: AppBar(),
body: Center(
child: Column(
children: [
Text("PAGE1"),
ElevatedButton(
onPressed: () {
Navigator.of(context, rootNavigator: true).push(
PageRouteBuilder(
pageBuilder: (_, _, _) => const Page2(),
transitionDuration: Duration.zero,
reverseTransitionDuration: Duration.zero,
),
);
},
child: Text("Go to Page2"),
),
],
),
),
);
}
}
class Page2 extends ConsumerWidget {
const Page2({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
print("[Widget Build] Page2");
return Scaffold(
appBar: AppBar(),
body: Center(child: Text("PAGE2")),
);
}
}OutputImportant NotesThe widgets don't even need to call ref.watch() or ref.read() to trigger this behavior QuestionIs this the intended behavior in Riverpod 3.0? If so, is there a way to opt-out of this for navigation scenarios where we want to preserve the previous behavior? The automatic provider pause/resume feature is great, but rebuilding every ConsumerWidget in the stack seems excessive. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
This should've been fixed in the latest 3.2.0 version |
Beta Was this translation helpful? Give feedback.
This should've been fixed in the latest 3.2.0 version