Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.

feat(nuxt): allow passing custom fetch options to useFetch#5660

Merged
pi0 merged 1 commit intonuxt:mainfrom
mrauhu:fetch-async-data-options
Jul 6, 2022
Merged

feat(nuxt): allow passing custom fetch options to useFetch#5660
pi0 merged 1 commit intonuxt:mainfrom
mrauhu:fetch-async-data-options

Conversation

@mrauhu
Copy link
Copy Markdown
Contributor

@mrauhu mrauhu commented Jun 29, 2022

Hello.

🔗 Linked issue

unjs/destr#9

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This fix needed to provide custom $fetch() options, like a providing custom parseResponse() function to fix the memory leak caused by destr() function:

import type { FetchOptions } from 'ohmyfetch';

/**
 * Parse response
 * @description Replace of `destr()` function to prevent memory leak
 * @param responseText
 */
const parseResponse: FetchOptions['parseResponse'] = (responseText) => {
  // Send empty string if zero length
  if (responseText.length === 0) {
    return '';
  }

  try {
    return JSON.parse(responseText);
  } catch (_e) {
    return responseText;
  }
};

// Example of usage
useFetch('/', {
  parseResponse,
};

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Best wishes,
Sergey.

…ch()` options and `useAsyncData()` options.

This needed to provide custom options for the `$fetch()` function.
@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 29, 2022

Deploy Preview for nuxt3-docs canceled.

Name Link
🔨 Latest commit 3fd2fed
🔍 Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/62bc63fd442a7f000811d5ec

@mrauhu mrauhu changed the title fix(nuxt): Allow providing custom $fetch() options via an options argument of the useFetch() function fix(nuxt): allow providing custom $fetch() options via an options argument of the useFetch() function Jun 29, 2022
@pi0 pi0 changed the title fix(nuxt): allow providing custom $fetch() options via an options argument of the useFetch() function feat(nuxt): allow passing custom fetch options to useFetch Jul 6, 2022
@pi0 pi0 merged commit 93d60a3 into nuxt:main Jul 6, 2022
@pi0
Copy link
Copy Markdown
Member

pi0 commented Jul 6, 2022

Thanks!

pi0 added a commit that referenced this pull request Jul 6, 2022
@pi0 pi0 mentioned this pull request Jul 11, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants