Skip to content
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

UseState reapplies initialValue on hot reload #453

Closed
BenjiFarquhar opened this issue Jan 3, 2025 · 2 comments
Closed

UseState reapplies initialValue on hot reload #453

BenjiFarquhar opened this issue Jan 3, 2025 · 2 comments
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@BenjiFarquhar
Copy link

BenjiFarquhar commented Jan 3, 2025

I'm noticing useState isn't playing nice with hot reload, as it re-applies the initial value on hot reload, but useMemoized behaves fine, not re-applying the initial state when hot reloading.

Not sure if this is intended, let me know if this is not considered a bug.

I was doing the code below with useState. After noticing this behaviour, i went with useMemoized.

class App extends HookConsumerWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final isAuthenticated = useMemoized(() => ValueNotifier<AsyncValue<bool>>(const AsyncLoading()));

flutter_hooks: 0.20.5
hooks_riverpod: 2.6.1

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.27.1, on macOS 15.1.1 24B91 darwin-arm64, locale en-GB)
    • Flutter version 3.27.1 on channel stable at /Users/benjaminfarquhar/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 17025dd882 (2 weeks ago), 2024-12-17 03:23:09 +0900
    • Engine revision cb4b5fff73
    • Dart version 3.6.0
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/benjaminfarquhar/Library/Android/sdk
    • Platform android-35, build-tools 34.0.0
    • ANDROID_HOME = /Users/benjaminfarquhar/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)

[✓] IntelliJ IDEA Community Edition (version 2024.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.96.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (6 available)
    • Benji’s iPhone 13 mini (mobile) • 00008110-001119123C7B801E            • ios            • iOS 18.1.1 22B91
    • iPad Pro 11-inch (M4) (mobile)  • 2DBCFED4-D6AE-4FAB-B86A-12CCF187513C • ios            • com.apple.CoreSimulator.SimRuntime.iOS-18-2 (simulator)
    • iPad Pro 13-inch (M4) (mobile)  • 0C0766EB-5379-4B6A-8A13-76B74049B8AB • ios            • com.apple.CoreSimulator.SimRuntime.iOS-18-2 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 15.1.1 24B91 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 15.1.1 24B91 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 131.0.6778.205

[✓] Network resources
    • All expected network resources are available.

• No issues found!
@rrousselGit
Copy link
Owner

I don't have any issue. The "problem" is likely somewhere else.

Do you have a complete example? Including the changes made to trigger hot-reload

@rrousselGit rrousselGit added question Further information is requested and removed needs triage labels Jan 3, 2025
@BenjiFarquhar
Copy link
Author

Hmm it isn't happening anymore, something will indeed have been wrong on my end, cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants