-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
skip fallback generation if prerendering is disabled - fixes #4492
- Loading branch information
1 parent
68f3650
commit fc6d9f9
Showing
9 changed files
with
196 additions
and
4 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
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,20 @@ | ||
{ | ||
"name": "prerendering-test-basics", | ||
"private": true, | ||
"version": "0.0.2-next.0", | ||
"scripts": { | ||
"dev": "node ../../cli.js dev", | ||
"build": "node ../../cli.js build", | ||
"preview": "node ../../cli.js preview", | ||
"check": "tsc && svelte-check", | ||
"test": "npm run build" | ||
}, | ||
"devDependencies": { | ||
"@sveltejs/kit": "workspace:*", | ||
"svelte": "^3.43.0", | ||
"svelte-check": "^2.5.0", | ||
"typescript": "~4.6.2", | ||
"uvu": "^0.5.2" | ||
}, | ||
"type": "module" | ||
} |
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,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
%svelte.head% | ||
</head> | ||
<body> | ||
%svelte.body% | ||
</body> | ||
</html> |
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 @@ | ||
throw new Error('this file should not be loaded if prerendering is disabled'); |
1 change: 1 addition & 0 deletions
1
packages/kit/test/prerendering/disabled/src/routes/index.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 @@ | ||
<h1>not prerendered</h1> |
1 change: 1 addition & 0 deletions
1
packages/kit/test/prerendering/disabled/static/file with spaces.json
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 @@ | ||
{ "answer": 42 } |
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,27 @@ | ||
import path from 'path'; | ||
import adapter from '../../../../adapter-static/index.js'; | ||
|
||
/** @type {import('@sveltejs/kit').Config} */ | ||
const config = { | ||
kit: { | ||
adapter: adapter(), | ||
|
||
prerender: { | ||
enabled: false | ||
}, | ||
|
||
vite: { | ||
build: { | ||
minify: false | ||
}, | ||
clearScreen: false, | ||
server: { | ||
fs: { | ||
allow: [path.resolve('../../../src')] | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export default config; |
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,117 @@ | ||
import fs from 'fs'; | ||
import { fileURLToPath } from 'url'; | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
|
||
const build = fileURLToPath(new URL('../build', import.meta.url)); | ||
|
||
/** @param {string} file */ | ||
const read = (file) => fs.readFileSync(`${build}/${file}`, 'utf-8'); | ||
|
||
test('prerenders /', () => { | ||
const content = read('index.html'); | ||
assert.ok(content.includes('<h1>hello</h1>')); | ||
}); | ||
|
||
test('renders a redirect', () => { | ||
const content = read('redirect.html'); | ||
assert.equal( | ||
content, | ||
'<meta http-equiv="refresh" content="0;url=https://example.com/redirected">' | ||
); | ||
}); | ||
|
||
test('does not double-encode redirect locations', () => { | ||
const content = read('redirect-encoded.html'); | ||
assert.equal( | ||
content, | ||
'<meta http-equiv="refresh" content="0;url=https://example.com/redirected?returnTo=%2Ffoo%3Fbar%3Dbaz">' | ||
); | ||
}); | ||
|
||
test('escapes characters in redirect', () => { | ||
const content = read('redirect-malicious.html'); | ||
assert.equal( | ||
content, | ||
'<meta http-equiv="refresh" content="0;url=https://example.com/</script>alert("pwned")">' | ||
); | ||
}); | ||
|
||
test('inserts http-equiv tag for cache-control headers', () => { | ||
const content = read('max-age.html'); | ||
assert.ok(content.includes('<meta http-equiv="cache-control" content="max-age=300">')); | ||
}); | ||
|
||
test('renders page with data from endpoint', () => { | ||
const content = read('fetch-endpoint/buffered.html'); | ||
assert.ok(content.includes('<h1>the answer is 42</h1>')); | ||
|
||
const json = read('fetch-endpoint/buffered.json'); | ||
assert.equal(json, JSON.stringify({ answer: 42 })); | ||
}); | ||
|
||
test('renders page with unbuffered data from endpoint', () => { | ||
const content = read('fetch-endpoint/not-buffered.html'); | ||
assert.ok(content.includes('<h1>content-type: application/json; charset=utf-8</h1>'), content); | ||
|
||
const json = read('fetch-endpoint/not-buffered.json'); | ||
assert.equal(json, JSON.stringify({ answer: 42 })); | ||
}); | ||
|
||
test('loads a file with spaces in the filename', () => { | ||
const content = read('load-file-with-spaces.html'); | ||
assert.ok(content.includes('<h1>answer: 42</h1>'), content); | ||
}); | ||
|
||
test('generates __data.json file for shadow endpoints', () => { | ||
assert.equal(read('__data.json'), JSON.stringify({ message: 'hello' })); | ||
assert.equal(read('shadowed-get/__data.json'), JSON.stringify({ answer: 42 })); | ||
}); | ||
|
||
test('does not prerender page with shadow endpoint with non-GET handler', () => { | ||
assert.ok(!fs.existsSync(`${build}/shadowed-post.html`)); | ||
assert.ok(!fs.existsSync(`${build}/shadowed-post/__data.json`)); | ||
}); | ||
|
||
test('decodes paths when writing files', () => { | ||
let content = read('encoding/path with spaces.html'); | ||
assert.ok(content.includes('<p id="a">path with spaces</p>')); | ||
assert.ok(content.includes('<p id="b">path with encoded spaces</p>')); | ||
|
||
content = read('encoding/dynamic path with spaces.html'); | ||
assert.ok( | ||
content.includes('<h1>dynamic path with spaces / /encoding/dynamic%20path%20with%20spaces</h1>') | ||
); | ||
|
||
content = read('encoding/dynamic path with encoded spaces.html'); | ||
assert.ok( | ||
content.includes( | ||
'<h1>dynamic path with encoded spaces / /encoding/dynamic%20path%20with%20encoded%20spaces</h1>' | ||
) | ||
); | ||
|
||
content = read('encoding/redirected path with encoded spaces.html'); | ||
assert.ok( | ||
content.includes( | ||
'<h1>redirected path with encoded spaces / /encoding/redirected%20path%20with%20encoded%20spaces</h1>' | ||
) | ||
); | ||
|
||
content = read('encoding/path with spaces.json'); | ||
assert.equal(content, JSON.stringify({ path: 'path with spaces' })); | ||
|
||
content = read('encoding/path with encoded spaces.json'); | ||
assert.equal(content, JSON.stringify({ path: 'path with encoded spaces' })); | ||
}); | ||
|
||
test('prerendering is set to true in global code of hooks.js', () => { | ||
const content = read('prerendering-true.html'); | ||
assert.ok(content.includes('<h1>prerendering: true/true</h1>'), content); | ||
}); | ||
|
||
test('fetching missing content results in a 404', () => { | ||
const content = read('fetch-404.html'); | ||
assert.ok(content.includes('<h1>status: 404</h1>'), content); | ||
}); | ||
|
||
test.run(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.