@sveltejs/kit 2.19.0 → 2.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "2.19.0",
3
+ "version": "2.19.1",
4
4
  "description": "SvelteKit is the fastest way to build Svelte apps",
5
5
  "keywords": [
6
6
  "framework",
@@ -2,6 +2,7 @@ import * as set_cookie_parser from 'set-cookie-parser';
2
2
  import { respond } from './respond.js';
3
3
  import * as paths from '__sveltekit/paths';
4
4
  import { read_implementation } from '__sveltekit/server';
5
+ import { has_prerendered_path } from './utils.js';
5
6
 
6
7
  /**
7
8
  * @param {{
@@ -112,10 +113,7 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade
112
113
  return await fetch(request);
113
114
  }
114
115
 
115
- if (
116
- manifest._.prerendered_routes.has(decoded) ||
117
- (decoded.at(-1) === '/' && manifest._.prerendered_routes.has(decoded.slice(0, -1)))
118
- ) {
116
+ if (has_prerendered_path(manifest, paths.base + decoded)) {
119
117
  // The path of something prerendered could match a different route
120
118
  // that is still in the manifest, leading to the wrong route being loaded.
121
119
  // We therefore bail early here. The prerendered logic is different for
@@ -5,7 +5,12 @@ import { render_page } from './page/index.js';
5
5
  import { render_response } from './page/render.js';
6
6
  import { respond_with_error } from './page/respond_with_error.js';
7
7
  import { is_form_content_type } from '../../utils/http.js';
8
- import { handle_fatal_error, method_not_allowed, redirect_response } from './utils.js';
8
+ import {
9
+ handle_fatal_error,
10
+ has_prerendered_path,
11
+ method_not_allowed,
12
+ redirect_response
13
+ } from './utils.js';
9
14
  import { decode_pathname, decode_params, disable_search, normalize_path } from '../../utils/url.js';
10
15
  import { exec } from '../../utils/routing.js';
11
16
  import { redirect_json_response, render_data } from './data/index.js';
@@ -21,6 +26,8 @@ import { get_public_env } from './env_module.js';
21
26
  import { resolve_route } from './page/server_routing.js';
22
27
  import { validateHeaders } from './validate-headers.js';
23
28
  import {
29
+ add_data_suffix,
30
+ add_resolution_suffix,
24
31
  has_data_suffix,
25
32
  has_resolution_suffix,
26
33
  strip_data_suffix,
@@ -191,6 +198,34 @@ export async function respond(request, options, manifest, state) {
191
198
  return text('Malformed URI', { status: 400 });
192
199
  }
193
200
 
201
+ if (
202
+ resolved_path !== url.pathname &&
203
+ !state.prerendering?.fallback &&
204
+ has_prerendered_path(manifest, resolved_path)
205
+ ) {
206
+ const url = new URL(request.url);
207
+ url.pathname = is_data_request
208
+ ? add_data_suffix(resolved_path)
209
+ : is_route_resolution_request
210
+ ? add_resolution_suffix(resolved_path)
211
+ : resolved_path;
212
+
213
+ // `fetch` automatically decodes the body, so we need to delete the related headers to not break the response
214
+ // Also see https://github.com/sveltejs/kit/issues/12197 for more info (we should fix this more generally at some point)
215
+ const response = await fetch(url, request);
216
+ const headers = new Headers(response.headers);
217
+ if (headers.has('content-encoding')) {
218
+ headers.delete('content-encoding');
219
+ headers.delete('content-length');
220
+ }
221
+
222
+ return new Response(response.body, {
223
+ headers,
224
+ status: response.status,
225
+ statusText: response.statusText
226
+ });
227
+ }
228
+
194
229
  /** @type {import('types').SSRRoute | null} */
195
230
  let route = null;
196
231
 
@@ -163,3 +163,15 @@ export function stringify_uses(node) {
163
163
 
164
164
  return `"uses":{${uses.join(',')}}`;
165
165
  }
166
+
167
+ /**
168
+ * Returns `true` if the given path was prerendered
169
+ * @param {import('@sveltejs/kit').SSRManifest} manifest
170
+ * @param {string} pathname Should include the base and be decoded
171
+ */
172
+ export function has_prerendered_path(manifest, pathname) {
173
+ return (
174
+ manifest._.prerendered_routes.has(pathname) ||
175
+ (pathname.at(-1) === '/' && manifest._.prerendered_routes.has(pathname.slice(0, -1)))
176
+ );
177
+ }
package/src/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // generated during release, do not modify
2
2
 
3
3
  /** @type {string} */
4
- export const VERSION = '2.19.0';
4
+ export const VERSION = '2.19.1';