Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 422b2e1

Browse filesBrowse files
authored
fixes #384 (#385)
1 parent 5a3f186 commit 422b2e1
Copy full SHA for 422b2e1

File tree

Expand file treeCollapse file tree

3 files changed

+55
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+55
-2
lines changed

‎packages/flutter_hooks/CHANGELOG.md

Copy file name to clipboardExpand all lines: packages/flutter_hooks/CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Unreleased patch
2+
3+
- Fixed key matching algorithm incorrectly not checking all keys if a 0 or a NaN is present (thanks to @AlexDochioiu)
4+
15
## 0.20.1 - 2023-08-29
26

37
- `useListenableSelector` now supports `null` listeners (thanks to @JWo1F)

‎packages/flutter_hooks/lib/src/framework.dart

Copy file name to clipboardExpand all lines: packages/flutter_hooks/lib/src/framework.dart
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,15 @@ Calling them outside of build method leads to an unstable state and is therefore
183183
if (curr1 is num && curr2 is num) {
184184
// Checks if both are NaN
185185
if (curr1.isNaN && curr2.isNaN) {
186-
return true;
186+
continue;
187187
}
188188

189189
// Checks if one is 0.0 and the other is -0.0
190190
if (curr1 == 0 && curr2 == 0) {
191-
return curr1.isNegative == curr2.isNegative;
191+
if (curr1.isNegative != curr2.isNegative) {
192+
return false;
193+
}
194+
continue;
192195
}
193196
}
194197

‎packages/flutter_hooks/test/use_effect_test.dart

Copy file name to clipboardExpand all lines: packages/flutter_hooks/test/use_effect_test.dart
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,29 @@ void main() {
268268
verifyNoMoreInteractions(effect);
269269
});
270270

271+
testWidgets(
272+
'calls effect when first key is two matching NaN but second key is different',
273+
(tester) async {
274+
// Regression test for https://github.com/rrousselGit/flutter_hooks/issues/384
275+
parameters = [double.nan, 0];
276+
await tester.pumpWidget(builder());
277+
278+
verifyInOrder([
279+
effect(),
280+
unrelated(),
281+
]);
282+
verifyNoMoreInteractions(effect);
283+
284+
parameters = [double.nan, 1];
285+
await tester.pumpWidget(builder());
286+
287+
verifyInOrder([
288+
effect(),
289+
unrelated(),
290+
]);
291+
verifyNoMoreInteractions(effect);
292+
});
293+
271294
testWidgets(
272295
'calls effect when one of keys is changed from 0.0 to -0.0 and vice versa',
273296
(tester) async {
@@ -298,6 +321,29 @@ void main() {
298321
]);
299322
verifyNoMoreInteractions(effect);
300323
});
324+
325+
testWidgets(
326+
'calls effect when first key is two matching 0 with same sign, but second key is different',
327+
(tester) async {
328+
// Regression test for https://github.com/rrousselGit/flutter_hooks/issues/384
329+
parameters = [-0, 42];
330+
await tester.pumpWidget(builder());
331+
332+
verifyInOrder([
333+
effect(),
334+
unrelated(),
335+
]);
336+
verifyNoMoreInteractions(effect);
337+
338+
parameters = [-0, 43];
339+
await tester.pumpWidget(builder());
340+
341+
verifyInOrder([
342+
effect(),
343+
unrelated(),
344+
]);
345+
verifyNoMoreInteractions(effect);
346+
});
301347
}
302348

303349
class MockEffect extends Mock {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.