forked from HoudiniGraphql/houdini
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve isFetching reliability (HoudiniGraphql#686)
* ⚡ FIX: setConfig already done in BaseStore * 🚸 IMPROVE: isFetching to happen only when a network call really happen. * ✏️ DOC: changeset * ✏️ DOC: changeset * ✅ UPDATE: with tests * track false fetching state when loading pages Co-authored-by: Alec Aivazis <[email protected]>
- Loading branch information
Showing
11 changed files
with
140 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'houdini': patch | ||
'houdini-react': patch | ||
'houdini-svelte': patch | ||
--- | ||
|
||
isFetching will switch only when a network call is happening (and starts at true for queries) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { routes } from '../../lib/utils/routes.js'; | ||
import { clientSideNavigation, goto, locator_click } from '../../lib/utils/testsHelper.js'; | ||
|
||
test.describe('isFetching', () => { | ||
test('with_load SSR', async ({ page }) => { | ||
const [msg] = await Promise.all([ | ||
page.waitForEvent('console'), | ||
goto(page, routes.isFetching_with_load) | ||
]); | ||
|
||
expect(msg.text()).toBe('with_load - isFetching: false'); | ||
}); | ||
|
||
test('with_load CSR', async ({ page }) => { | ||
await goto(page, routes.Home); | ||
|
||
// Switch page and check directly the first console log | ||
const [msg] = await Promise.all([ | ||
page.waitForEvent('console'), | ||
clientSideNavigation(page, routes.isFetching_with_load) | ||
]); | ||
expect(msg.text()).toBe('with_load - isFetching: true'); | ||
|
||
// wait for the isFetching false | ||
const msg2 = await page.waitForEvent('console'); | ||
expect(msg2.text()).toBe('with_load - isFetching: false'); | ||
}); | ||
|
||
test('without_load CSR', async ({ page }) => { | ||
await goto(page, routes.Home); | ||
|
||
// Switch page and check the first console log | ||
// It's expected to stay true until the first fetch! | ||
const [msg] = await Promise.all([ | ||
page.waitForEvent('console'), | ||
clientSideNavigation(page, routes.isFetching_without_load) | ||
]); | ||
expect(msg.text()).toBe('without_load - isFetching: true'); | ||
|
||
const [msg2] = await Promise.all([ | ||
page.waitForEvent('console'), | ||
// manual fetch | ||
locator_click(page, 'button') | ||
]); | ||
expect(msg2.text()).toBe('without_load - isFetching: true'); | ||
|
||
// wait for the isFetching false | ||
const msg3 = await page.waitForEvent('console'); | ||
expect(msg3.text()).toBe('without_load - isFetching: false'); | ||
|
||
// second click should not refetch... so isFetching should be false | ||
const [msg4] = await Promise.all([ | ||
page.waitForEvent('console'), | ||
// manual fetch | ||
locator_click(page, 'button') | ||
]); | ||
expect(msg4.text()).toBe('without_load - isFetching: false'); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
e2e/sveltekit/src/routes/isFetching/with_load/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<script lang="ts"> | ||
import { graphql } from '$houdini'; | ||
const store = graphql` | ||
query isFetching_w { | ||
user(id: 1, snapshot: "isFetching_w", delay: 200) { | ||
id | ||
name | ||
} | ||
} | ||
`; | ||
$: console.log(`with_load - isFetching: ${$store.isFetching}`); | ||
</script> | ||
|
||
<pre>{JSON.stringify($store, null, 2)}</pre> |
22 changes: 22 additions & 0 deletions
22
e2e/sveltekit/src/routes/isFetching/without_load/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<script lang="ts"> | ||
import { graphql } from '$houdini'; | ||
const store = graphql` | ||
query isFetching_wo @houdini(load: false) { | ||
user(id: 1, snapshot: "isFetching_wo", delay: 200) { | ||
id | ||
name | ||
} | ||
} | ||
`; | ||
const getData = () => { | ||
store.fetch(); | ||
}; | ||
$: console.log(`without_load - isFetching: ${$store.isFetching}`); | ||
</script> | ||
|
||
<button on:click={getData}>Fetch</button> | ||
|
||
<pre>{JSON.stringify($store, null, 2)}</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters