Skip to content

fix: Always include root layout/error nodes in manifest #13522

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/long-hounds-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: Include root layout and error nodes even when apps have only prerendered pages
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"pnpm": {
"onlyBuiltDependencies": [
"svelte-preprocess",
"workerd"
"workerd",
"esbuild"
]
}
}
}
6 changes: 2 additions & 4 deletions packages/kit/src/core/generate_manifest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ export function generate_manifest({ build_data, prerendered, relative_path, rout
const reindexed = new Map();
/**
* All nodes actually used in the routes definition (prerendered routes are omitted).
* If `routes` is empty, it means that this manifest is only used for server-side resolution
* and the root layout/error is therefore not needed.
* Else, root layout/error is always included as they are needed for 404 and root errors.
* Root layout/error is always included as they are needed for 404 and root errors.
* @type {Set<any>}
*/
const used_nodes = new Set(routes.length > 0 ? [0, 1] : []);
const used_nodes = new Set([0, 1]);

const server_assets = find_server_assets(build_data, routes);

Expand Down
3 changes: 3 additions & 0 deletions packages/kit/test/apps/prerendered-app-error-pages/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/test/errors.json
!/.env
/src/routes/routing/symlink-from
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Please do not edit this app unless you're absolutely sure it's not going to affect the tests.
19 changes: 19 additions & 0 deletions packages/kit/test/apps/prerendered-app-error-pages/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"moduleResolution": "bundler"
}
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
}
26 changes: 26 additions & 0 deletions packages/kit/test/apps/prerendered-app-error-pages/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "test-prerendered-app-error-pages",
"private": true,
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"prepare": "svelte-kit sync || echo ''",
"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch",
"test": "pnpm test:dev && pnpm test:build",
"test:dev": "cross-env DEV=true playwright test",
"test:build": "playwright test"
},
"devDependencies": {
"@sveltejs/kit": "workspace:^",
"@sveltejs/vite-plugin-svelte": "^5.0.1",
"cross-env": "^7.0.3",
"svelte": "^5.2.9",
"svelte-check": "^4.1.1",
"typescript": "^5.5.4",
"vite": "^6.0.11"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { config as default } from '../../utils.js';
13 changes: 13 additions & 0 deletions packages/kit/test/apps/prerendered-app-error-pages/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://svelte.dev/docs/kit/types#app.d.ts
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}

export {};
12 changes: 12 additions & 0 deletions packages/kit/test/apps/prerendered-app-error-pages/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>This is your custom error page.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const prerender = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>
This app exists to assert that an app with only prerendered routes successfully renders custom
error pages.
</p>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {}
};

export default config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { expect } from '@playwright/test';
import { test } from '../../../utils.js';

test.describe.configure({ mode: 'parallel' });

test('renders error page on nonexistent route', async ({ page }) => {
await page.goto('/nonexistent', { wait_for_started: false });
expect(await page.textContent('p')).toBe('This is your custom error page.');
});
12 changes: 12 additions & 0 deletions packages/kit/test/apps/prerendered-app-error-pages/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { sveltekit } from '@sveltejs/kit/vite';
import path from 'node:path';
import { defineConfig } from 'vite';

export default defineConfig({
plugins: [sveltekit()],
server: {
fs: {
allow: [path.resolve('../../../src')]
}
}
});
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading