Skip to content

Commit cc2ec79

Browse files
committed
fix(flutter): apply grants across enable rebuilds
1 parent c039a27 commit cc2ec79

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

sdks/flutter/packages/tugboat/lib/src/tugboat.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ class _TugboatActivationGateState extends State<_TugboatActivationGate> {
367367
super.didUpdateWidget(oldWidget);
368368
if (oldWidget.config.enabled != widget.config.enabled) {
369369
_syncCaptureFlag();
370-
} else if (_captureMounted &&
370+
}
371+
if (_captureMounted &&
371372
_capabilitiesChanged(oldWidget.config, widget.config)) {
372373
_mountedEpoch = TugboatReplay._lifecycle.beginCapabilityRemount();
373374
}

sdks/flutter/packages/tugboat/test/tugboat_replay_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,44 @@ void main() {
14641464
expect(TugboatReplay.lifecycleState, TugboatLifecycleState.active);
14651465
});
14661466

1467+
testWidgets('runtime capture applies a combined enable and grant rebuild', (
1468+
tester,
1469+
) async {
1470+
addTearDown(TugboatReplay.resetForTest);
1471+
final upgraded = ValueNotifier<bool>(false);
1472+
addTearDown(upgraded.dispose);
1473+
1474+
await tester.pumpWidget(
1475+
ValueListenableBuilder<bool>(
1476+
valueListenable: upgraded,
1477+
builder: (context, value, _) => MaterialApp(
1478+
builder: (context, child) => TugboatReplay.wrapApp(
1479+
config: _testConfig.copyWith(
1480+
enabled: value,
1481+
emitSceneInventory: value,
1482+
),
1483+
child: child!,
1484+
),
1485+
home: const Scaffold(body: Text('Combined grant')),
1486+
),
1487+
),
1488+
);
1489+
await tester.pump();
1490+
expect(TugboatReplay.controller, isNull);
1491+
1492+
TugboatReplay.activate(activationRequestId: 'combined-grant');
1493+
await _waitForCaptures(tester);
1494+
final runtimeController = TugboatReplay.controller!;
1495+
expect(runtimeController.config.emitSceneInventory, isFalse);
1496+
1497+
upgraded.value = true;
1498+
await _waitForCaptures(tester);
1499+
final upgradedController = TugboatReplay.controller!;
1500+
expect(upgradedController, isNot(same(runtimeController)));
1501+
expect(upgradedController.config.emitSceneInventory, isTrue);
1502+
expect(TugboatReplay.lifecycleState, TugboatLifecycleState.active);
1503+
});
1504+
14671505
testWidgets('disabled config stays inert until activated without rebuild', (
14681506
tester,
14691507
) async {

0 commit comments

Comments
 (0)