From 1ecf84e77e61dbb4b896e15a5ccc731180680cb3 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sat, 26 Nov 2022 20:52:20 -0800 Subject: [PATCH] log --- packages/kit/src/runtime/client/client.js | 2 ++ packages/kit/src/runtime/client/fetcher.js | 7 +++--- .../kit/test/apps/basics/test/client.test.js | 24 ++++++++----------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/packages/kit/src/runtime/client/client.js b/packages/kit/src/runtime/client/client.js index 7d8c8ea940e6e..d131a74fd320e 100644 --- a/packages/kit/src/runtime/client/client.js +++ b/packages/kit/src/runtime/client/client.js @@ -647,6 +647,7 @@ export function create_client({ target, base }) { }); if (import.meta.env.DEV) { +console.warn('loading node'); try { lock_fetch(); data = (await node.shared.load.call(null, load_input)) ?? null; @@ -1521,6 +1522,7 @@ export function create_client({ target, base }) { }, _hydrate: async ({ status, error, node_ids, params, route, data: server_data_nodes, form }) => { +console.warn(`hydrating`); hydrated = true; const url = new URL(location.href); diff --git a/packages/kit/src/runtime/client/fetcher.js b/packages/kit/src/runtime/client/fetcher.js index 552bae15eaddf..c06f3583c1472 100644 --- a/packages/kit/src/runtime/client/fetcher.js +++ b/packages/kit/src/runtime/client/fetcher.js @@ -11,7 +11,7 @@ export function lock_fetch() { export function unlock_fetch() { loading -= 1; } - +console.warn(`initializing fetcher ${import.meta.env.DEV}`); if (import.meta.env.DEV) { let can_inspect_stack_trace = false; @@ -23,11 +23,12 @@ if (import.meta.env.DEV) { check_stack_trace(); window.fetch = (input, init) => { - const url = input instanceof Request ? input.url : input.toString(); const stack = /** @type {string} */ (new Error().stack); - const heuristic = can_inspect_stack_trace ? stack.includes('load_node') : loading; +console.warn(`doing fetch. heuristic: ${!!heuristic}. can_inspect_stack_trace: ${!!can_inspect_stack_trace}. loading: ${loading}`); +console.warn(stack); if (heuristic) { + const url = input instanceof Request ? input.url : input.toString(); console.warn( `Loading ${url} using \`window.fetch\`. For best results, use the \`fetch\` that is passed to your \`load\` function: https://kit.svelte.dev/docs/load#making-fetch-requests` ); diff --git a/packages/kit/test/apps/basics/test/client.test.js b/packages/kit/test/apps/basics/test/client.test.js index 29b706f3172a1..103855f3437fd 100644 --- a/packages/kit/test/apps/basics/test/client.test.js +++ b/packages/kit/test/apps/basics/test/client.test.js @@ -608,28 +608,24 @@ test.describe('Load', () => { if (process.env.DEV) { test('using window.fetch causes a warning', async ({ page, baseURL }) => { - await Promise.all([ - page.goto('/load/window-fetch/incorrect'), - page.waitForEvent('console', { - predicate: (message) => { - return ( - message.text() === - `Loading ${baseURL}/load/window-fetch/data.json using \`window.fetch\`. For best results, use the \`fetch\` that is passed to your \`load\` function: https://kit.svelte.dev/docs/load#making-fetch-requests` - ); - }, - timeout: 3_000 - }) - ]); - expect(await page.textContent('h1')).toBe('42'); - /** @type {string[]} */ const warnings = []; + page.on('console', (msg) => { if (msg.type() === 'warning') { warnings.push(msg.text()); } }); + await page.goto('/load/window-fetch/incorrect'); + expect(await page.textContent('h1')).toBe('42'); + + expect(warnings).toContain( + `Loading ${baseURL}/load/window-fetch/data.json using \`window.fetch\`. For best results, use the \`fetch\` that is passed to your \`load\` function: https://kit.svelte.dev/docs/load#making-fetch-requests` + ); + + warnings.length = 0; + await page.goto('/load/window-fetch/correct'); expect(await page.textContent('h1')).toBe('42');