Skip to content

Commit

Permalink
fix: set useFetch delay to 0 by default (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
manniL committed Feb 4, 2021
1 parent 42b93db commit 33b9790
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/fetch.ts
Expand Up @@ -234,7 +234,7 @@ export const useFetch = (callback: Fetch) => {
}

vm._fetchDelay =
typeof vm.$options.fetchDelay === 'number' ? vm.$options.fetchDelay : 200
typeof vm.$options.fetchDelay === 'number' ? vm.$options.fetchDelay : 0

vm.$fetch = callFetches.bind(vm)

Expand Down
10 changes: 10 additions & 0 deletions test/e2e/fetch.ts
Expand Up @@ -40,6 +40,16 @@ test('Refetches with $fetch', async t => {
await expectOnPage('loading email')
})

test('TTFB is lower than 100ms', async t => {
await navigateTo('/ttfb')
const ttfbRegex = /TTFB: (\d+)ms/
const selector = await Selector('*').withText(new RegExp(ttfbRegex, 'i'))
const text = await selector.innerText
const [, msString] = /TTFB: (\d+)ms/.exec(text)!
const ms = Number(msString)
await t.expect(ms).lte(100)
})

test("Doesn't overwrite methods and getters", async () => {
await navigateTo('/')
await expectOnPage('computed')
Expand Down
10 changes: 10 additions & 0 deletions test/fixture/pages/index.vue
Expand Up @@ -41,6 +41,9 @@
</li>
<li><nuxt-link to="/meta">meta</nuxt-link></li>
</ul>
<div>
TTFB: {{ ttfb }}ms
</div>
</main>
</template>

Expand All @@ -50,6 +53,7 @@ import {
ref,
computed,
useFetch,
onMounted
} from '@nuxtjs/composition-api'
import ChildComp from '../components/comp.vue'
Expand All @@ -73,11 +77,17 @@ export default defineComponent({
if (process.client) email.value = await fetcher('long@load.com', 2000)
})
const ttfb = ref(-1)
onMounted(() => {
ttfb.value = globalThis.performance.getEntriesByType('navigation')[0].responseStart
})
return {
name,
email,
computedProp,
myFunction,
ttfb
}
},
})
Expand Down
33 changes: 33 additions & 0 deletions test/fixture/pages/ttfb.vue
@@ -0,0 +1,33 @@
<template>
<main>
TTFB: {{ ttfb }}ms
</main>
</template>

<script>
import {
defineComponent,
ref,
computed,
useFetch,
onMounted
} from '@nuxtjs/composition-api'
import ChildComp from '../components/comp.vue'
import { fetcher } from '../utils'
export default defineComponent({
setup() {
useFetch(() => {})
const ttfb = ref(-1)
onMounted(() => {
ttfb.value = globalThis.performance.getEntriesByType('navigation')[0].responseStart
})
return {
ttfb
}
},
})
</script>

1 comment on commit 33b9790

@vercel
Copy link

@vercel vercel bot commented on 33b9790 Feb 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.