-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: support absolute URLs with data-sveltekit-preload-code="viewport"
#12217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
f248887
f5652af
e99756a
4c961cc
41a5e11
b8542ac
f4afd8e
a80b9f4
0267335
1a58e98
940f904
8d7c226
eff1216
947c6b7
4c9b8d0
649bbf9
5fdc730
48791e3
467e53a
1e99146
0ee85a3
305d577
a833d9f
d12c376
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@sveltejs/kit": patch | ||
| --- | ||
|
|
||
| fix: support absolute URLs with `data-sveltekit-preload-code="viewport"` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <div style="height: 200vh"></div> | ||
|
|
||
| <a | ||
| id="viewport" | ||
| href="/data-sveltekit/preload-code/target/viewport" | ||
| data-sveltekit-preload-code="viewport">viewport</a | ||
| > | ||
| <a id="hover" href="/data-sveltekit/preload-code/target/hover" data-sveltekit-preload-code="hover" | ||
| >hover</a | ||
| > | ||
| <a id="tap" href="/data-sveltekit/preload-code/target/tap" data-sveltekit-preload-code="tap">tap</a> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export function load() { | ||
| return { | ||
| name: 'eager' | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <script> | ||
| export let data; | ||
| </script> | ||
|
|
||
| <h1>{data.name}</h1> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export function load() { | ||
| return { | ||
| name: 'hover' | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <script> | ||
| export let data; | ||
| </script> | ||
|
|
||
| <h1>{data.name}</h1> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export function load() { | ||
| return { | ||
| name: 'tap' | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <script> | ||
| export let data; | ||
| </script> | ||
|
|
||
| <h1>{data.name}</h1> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export function load() { | ||
| return { | ||
| name: 'hover' | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <script> | ||
| export let data; | ||
| </script> | ||
|
|
||
| <h1>{data.name}</h1> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -619,6 +619,36 @@ test.describe('Invalidation', () => { | |
| }); | ||
|
|
||
| test.describe('data-sveltekit attributes', () => { | ||
| test('data-sveltekit-preload-code', async ({ page }) => { | ||
| /** @type {string[]} */ | ||
| const requests = []; | ||
| page.on('request', (r) => { | ||
| requests.push(r.url()); | ||
| }); | ||
|
|
||
| // eager | ||
| await page.goto('/data-sveltekit/preload-code'); | ||
| expect(requests.length).toBeGreaterThanOrEqual(1); | ||
|
|
||
| // viewport | ||
| requests.length = 0; | ||
| page.locator('#viewport').scrollIntoViewIfNeeded(); | ||
| await Promise.all([page.waitForTimeout(100), page.waitForLoadState('networkidle')]); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It was used in the I'll remove the waitForTimeout because they are not needed here
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it may be needed here just so that there's time for the network requests to fire. Removing them causes the tests to fail with 0 network requests. Other preload tests have the same pattern. |
||
| expect(requests.length).toBeGreaterThanOrEqual(1); | ||
|
|
||
| // hover | ||
| requests.length = 0; | ||
| await page.locator('#hover').dispatchEvent('mousemove'); | ||
| await Promise.all([page.waitForTimeout(100), page.waitForLoadState('networkidle')]); | ||
| expect(requests.length).toBeGreaterThanOrEqual(1); | ||
|
|
||
| // tap | ||
| requests.length = 0; | ||
| await page.locator('#tap').dispatchEvent('touchstart'); | ||
| await Promise.all([page.waitForTimeout(100), page.waitForLoadState('networkidle')]); | ||
| expect(requests.length).toBeGreaterThanOrEqual(1); | ||
| }); | ||
|
|
||
| test('data-sveltekit-preload-data', async ({ page }) => { | ||
| /** @type {string[]} */ | ||
| const requests = []; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.