Skip to content

state_referenced_locally warning when trying to store an initial value #12877

Closed as not planned
@bienoubien-studio

Description

@bienoubien-studio

Describe the bug

Not sure if i am using runes as it should be, but I get : State referenced in its own scope will never update. Did you mean to reference it inside a closure? (state_referenced_locally) when trying to store an initial value from a state

const { path } = $props()
const form = getFormContext()
const field = $derived(form.useField(path)) // access some usefull methods here depending on the path prop
const initialValue = field.value // <— warning here
const initialValue = $state.snapshot(field.value) // <— warning also

I know initialValue won't change and this is what I am expected

What am I doing wrong ?

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE41UbYucMBD-K4MU1MPT9lvxVCgHhbb0hRb6Zfc-ZHXcCxcTScbrbcX_XpLo6W6P0l12yGaePDN5ZiZj0HKBJsh3YyBZh0EevOv7IAno1Ns_5hEFYZAERg26tjuFqTXvqdrLPfGuV5rgg5SoodWqgzDN3L_UHwwtyv5qJQ3BA54MlLALWZhAeLCmtqaxBq1pw7sVfkT6zmSjuk94ghKiGMrKcew-M7pPW6GUjtxSO1gUw5XzpwLlke7ju70EsHwCCXpG91DCK0OMMNpyR3F8nmd9z-QRv_kDPuzoEDSTnJ-2rskzFNkqjywOA5GSoGQteP1QjivvVPm1y6rIPLAqDjqr9rLwglpXOVo7QVYFSdCphrccmyAnPeCUPJfM4f-3aP6Ko9djsor0WvXGXUPuKbu6gut_f7wUtxoZ4Xulux9WUeAGWE0DE-IErdIdMAn4RKglE2C7LAF8yp1r7o6UjKvOVWZtO8iauJJQXxBHsVXfF9KXslH1WskRWA6hkrZ_DjmE9EuFCdR5SBrtXpOHrRp0mADmYcsf7V6bh4Y_hVN840mtBfDKDAbfcxSNLb3VaC0_AIBGGrRc2sF-DRI8MjFg5Gy8ce2pUfXOktxB6UGrc0oWTrD9NHPEa6hNuGeam9U5Lctp3pzOLnOZ6NHrFm3zW9mXvTWpRYZkS-7tSy0Cvohrg7kWKC-L6YdlRswqv2pQ80dsItcaS1yv_QbOJSfOxE8rE5T-dLpquu0gJT_IfqDouRgbMJSAKTF9RFpPT5eTK9gBhb1DuQ-45doHlYucF5nz2TF1DuDNigEl3aoc5xQmX9Zy3GZvx9lF6avbQWuU8-OUg5_2Iusr5z27cg7nJDOqVg26uR4__vj6JTWkuTzy9uTVbFQdu8stMFkYOgmcX4IGZ4EabnrBTvlBqPph7qOO6SOX16T6_I3G7ub5mXMCLMoqSdeG_8YcXqdvF9jLhy_CrMK7jP5-4O6mP2Q2eaWfBgAA

Logs

No response

System Info

System:
    OS: macOS 14.4.1
    CPU: (8) arm64 Apple M2
    Memory: 84.00 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.5.1 - ~/.nvm/versions/node/v22.5.1/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v22.5.1/bin/npm
    pnpm: 9.1.1 - /opt/homebrew/bin/pnpm
    bun: 1.1.17 - /opt/homebrew/bin/bun
  Browsers:
    Brave Browser: 127.1.68.137
    Chrome: 124.0.6367.208
    Safari: 17.4.1
  npmPackages:
    svelte: 5.0.0-next.222 => 5.0.0-next.222

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions