question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

null response on load of the nested child when using useLazyFetch on bridge

See original GitHub issue

Discussed in https://github.com/nuxt/framework/discussions/3083

<div type='discussions-op-text'>

Originally posted by csechuan February 7, 2022

Reproduction

https://github-rxxzhp-cpxf9c–3000.local.webcontainer.io/

Steps

  1. Open your console
  2. Click “Go cinema”
  3. Click “Watch movie”
// console output
movie env client res {"data":{"value":null},"pending":{"value":true},"error":{"value":null}}
  1. Click “Back”
  2. Click “Go cinema” again
// console output
movie env client res {"data":{"value":{A_LOT_OF_DATA_HERE}},"pending":{"value":true},"error":{"value":null}}

// check the network tab for movie. you should see the API response fine.
  1. Repeating steps 4-5 will have the same result

Description of the bug

Fetch response does not have data on first try. Subsequently it prints some data.

Additional context

Besides, i found another bug during debugging this issue. The pending flag is always true when useLazyFetch runs on client. I may not use the function correctly.

<script setup>
// since vue2 on nuxt bridge cant use top-level await
useLazyFetch('URL_HERE').then(res => console.log(res))
</script>
</div>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
danielroecommented, Mar 8, 2022

The data from useLazyFetch isn’t meant to be used within the setup function (that’s why it’s lazy). Instead it returns a reactive ref that gets filled in later. So you handle it like this: https://v3.nuxtjs.org/docs/usage/data-fetching#example-3

0reactions
csechuancommented, Mar 8, 2022

sorry. terrible mistake. didnt notice that. try this

https://stackblitz.com/edit/github-rxxzhp-cpxf9c

Read more comments on GitHub >

github_iconTop Results From Across the Web

nuxt.js - Why does useLazyFetch composable returns null data?
I am trying to learn how to use the ...
Read more >
Learn All About PHP Functions with Examples
In this article, we will learn about PHP functions together with examples. ... When a page loads, a feature will not run automatically....
Read more >
nuxt: Versions | Openbase
Nuxt's node server renderer will now respond with 103 Early Hints before the server ... nuxt: Load payload after middleware and once final...
Read more >
Data Fetching · Get Started with Nuxt
It automatically generates a key based on URL and fetch options, provides type hints for request url based on server routes, and infers...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found