Skip to content

There is a problem with the auto-generated key of useFetch () #14447

Closed as not planned
@tghkuma

Description

Environment


  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.6
  • Package Manager: npm@7.17.0
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

stackblitz

Describe the bug

The auto-generated key implemented in nuxt/framework#4955 is fixed at the line where useFetch () is called.
Therefore, calling useFetch () inside a wrapped function will enable caching.
Is it possible to make a unique key including the request?

Additional context

Results of stackblitz

Test1: Direst useFetch()
test1_1:{ "data": "result:1", "pending": false, "error": null }
test1_2:{ "data": "result:2", "pending": false, "error": null }
test1_3:{ "data": "result:3", "pending": false, "error": null }
Test2: Promise.all([useFetch(),...]) Different autoKey
test2_1:{ "data": "result:1", "pending": false, "error": null }
test2_2:{ "data": "result:2", "pending": false, "error": null }
test2_3:{ "data": "result:3", "pending": false, "error": null }
Test3: commonFetch() Same autoKey(Failed)
test3_1:{ "data": "result:1", "pending": false, "error": null }
test3_2:{ "data": "result:1", "pending": false, "error": null }
test3_3:{ "data": "result:1", "pending": false, "error": null }
Test4: Promise.all([commonFetch(),...]) Same autoKey(Failed)
test4_1:{ "data": "result:1", "pending": false, "error": null }
test4_2:{ "data": "result:1", "pending": false, "error": null }
test4_3:{ "data": "result:1", "pending": false, "error": null }
Test5: Promise.all([commonFetch(),...]) User-defined key
test5_1:{ "data": "result:1", "pending": false, "error": null }
test5_2:{ "data": "result:2", "pending": false, "error": null }
test5_3:{ "data": "result:3", "pending": false, "error": null }

auto-generated key example

Test1
/api/test?param=1 $4MofPlRIqc
/api/test?param=2 $c1QuMb3hkj
/api/test?param=3 $eACxAi6gXG
Test2
/api/test?param=1 $qpZVS1fTjL
/api/test?param=2 $AWmYgTxpCS
/api/test?param=3 $zoL2o86MUu
Test3
/api/test?param=1 $QePu11El1i
/api/test?param=2 $QePu11El1i
/api/test?param=3 $QePu11El1i
Test4
/api/test?param=1 $QePu11El1i
/api/test?param=2 $QePu11El1i
/api/test?param=3 $QePu11El1i
Test5
/api/test?param=1 key1
/api/test?param=2 key2
/api/test?param=3 key3

Logs

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions