import { expect } from '@playwright/test' import { test } from '@tanstack/router-e2e-utils' test.describe('Async Script Hydration', () => { test('should not show hydration warning for async scripts', async ({ page, }) => { await page.goto('/async-scripts') await expect( page.getByTestId('async-scripts-test-heading'), ).toBeInViewport() await page.waitForFunction(() => (window as any).SCRIPT_1 === true) }) test('should load async and defer scripts correctly', async ({ page }) => { await page.goto('/async-scripts') await expect( page.getByTestId('async-scripts-test-heading'), ).toBeInViewport() // script.js (async) sets window.SCRIPT_1 = true // script2.js (defer) sets window.SCRIPT_2 = true expect(await page.evaluate('window.SCRIPT_1')).toBe(true) expect(await page.evaluate('window.SCRIPT_2')).toBe(true) }) }) test.describe('Script Duplication Prevention', () => { test('should not create duplicate scripts on SSR route', async ({ page }) => { await page.goto('/scripts') await expect(page.getByTestId('scripts-test-heading')).toBeInViewport() // Wait for the script to execute — React 19 hoists