Open History to see the last commit
1import { expect } from '@playwright/test'
2import { test } from '@tanstack/router-e2e-utils'
3β
4// if the query would not be streamed to the client, it would re-execute on the client
5// and thus cause a hydration mismatch since the query function returns 'client' when executed on the client
6test.describe('queries are streamed from the server', () => {
7 test('direct visit - loader on server runs fetchQuery and awaits it', async ({
8 page,
9 }) => {
10 await page.goto('/loader-fetchQuery/sync')
11β
12 // wait for the query data to be streamed from the server
13 const queryData = page.getByTestId('query-data')
14 await expect(queryData).toHaveText('server')
15β
16 // the loader data should be the same as the query data
17 const loaderData = page.getByTestId('loader-data')
18 await expect(loaderData).toHaveText('server')
19 })
20 test('direct visit - loader on server runs fetchQuery and does not await it', async ({
21 page,
22 }) => {
23 await page.goto('/loader-fetchQuery/async')
24β
25 // wait for the query data to be streamed from the server
26 const queryData = page.getByTestId('query-data')
27 await expect(queryData).toHaveText('server')
28β
29 const loaderData = page.getByTestId('loader-data')
30 await expect(loaderData).toHaveText('undefined')
31 })
32β
33 test('useSuspenseQuery', async ({ page }) => {
34 await page.goto('/useSuspenseQuery')
35β
36 const queryData = page.getByTestId('query-data')
37 await expect(queryData).toHaveText('server')
38 })
39})
40β
41test('useQuery does not execute on the server and therefore does not stream data to the client', async ({
42 page,
43}) => {
44 await page.goto('/useQuery')
45β
46 const queryData = page.getByTestId('query-data')
47 await expect(queryData).toHaveText('client')
48})