@sveltejs/kit 1.11.0 → 1.13.0

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": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -22,7 +22,7 @@
22
22
  "set-cookie-parser": "^2.5.1",
23
23
  "sirv": "^2.0.2",
24
24
  "tiny-glob": "^0.2.9",
25
- "undici": "5.20.0"
25
+ "undici": "5.21.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@playwright/test": "^1.29.2",
@@ -34,11 +34,11 @@
34
34
  "@types/set-cookie-parser": "^2.4.2",
35
35
  "marked": "^4.2.3",
36
36
  "rollup": "^3.7.0",
37
- "svelte": "^3.55.1",
37
+ "svelte": "^3.56.0",
38
38
  "svelte-preprocess": "^5.0.0",
39
39
  "typescript": "^4.9.4",
40
40
  "uvu": "^0.5.6",
41
- "vite": "^4.1.1"
41
+ "vite": "^4.2.0"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "svelte": "^3.54.0",
@@ -6,6 +6,11 @@
6
6
 
7
7
  <style>
8
8
  body {
9
+ --bg: white;
10
+ --fg: #222;
11
+ --divider: #ccc;
12
+ background: var(--bg);
13
+ color: var(--fg);
9
14
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
10
15
  Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
11
16
  display: flex;
@@ -30,7 +35,7 @@
30
35
  }
31
36
 
32
37
  .message {
33
- border-left: 1px solid #ccc;
38
+ border-left: 1px solid var(--divider);
34
39
  padding: 0 0 0 1rem;
35
40
  margin: 0 0 0 1rem;
36
41
  min-height: 2.5rem;
@@ -43,6 +48,14 @@
43
48
  font-size: 1em;
44
49
  margin: 0;
45
50
  }
51
+
52
+ @media (prefers-color-scheme: dark) {
53
+ body {
54
+ --bg: #222;
55
+ --fg: #ddd;
56
+ --divider: #666;
57
+ }
58
+ }
46
59
  </style>
47
60
  </head>
48
61
  <body>
@@ -179,12 +179,15 @@ export function crawl(html, base) {
179
179
  let insideURL = true;
180
180
  value = value.trim();
181
181
  for (let i = 0; i < value.length; i++) {
182
- if (value[i] === ',' && (!insideURL || (insideURL && value[i + 1] === ' '))) {
182
+ if (
183
+ value[i] === ',' &&
184
+ (!insideURL || (insideURL && WHITESPACE.test(value[i + 1])))
185
+ ) {
183
186
  candidates.push(value.slice(0, i));
184
187
  value = value.substring(i + 1).trim();
185
188
  i = 0;
186
189
  insideURL = true;
187
- } else if (value[i] === ' ') {
190
+ } else if (WHITESPACE.test(value[i])) {
188
191
  insideURL = false;
189
192
  }
190
193
  }
@@ -176,7 +176,12 @@ function load_user_tsconfig(cwd) {
176
176
  function validate_user_config(kit, cwd, out, config) {
177
177
  // we need to check that the user's tsconfig extends the framework config
178
178
  const extend = config.options.extends;
179
- const extends_framework_config = extend && path.resolve(cwd, extend) === out;
179
+ const extends_framework_config =
180
+ typeof extend === 'string'
181
+ ? path.resolve(cwd, extend) === out
182
+ : Array.isArray(extend)
183
+ ? extend.some((e) => path.resolve(cwd, e) === out)
184
+ : false;
180
185
 
181
186
  const options = config.options.compilerOptions || {};
182
187
 
@@ -91,7 +91,8 @@ export function enhance(form, submit = () => {}) {
91
91
  cancel,
92
92
  controller,
93
93
  data,
94
- form
94
+ form,
95
+ submitter: event.submitter
95
96
  })) ?? fallback_callback;
96
97
  if (cancelled) return;
97
98
 
@@ -35,6 +35,8 @@ import { validate_common_exports } from '../../utils/exports.js';
35
35
  import { compact } from '../../utils/array.js';
36
36
  import { validate_depends } from '../shared.js';
37
37
 
38
+ let errored = false;
39
+
38
40
  // We track the scroll position associated with each history entry in sessionStorage,
39
41
  // rather than on history.state itself, because when navigation is driven by
40
42
  // popstate it's too late to update the scroll position associated with the
@@ -277,6 +279,9 @@ export function create_client(app, target) {
277
279
  let navigation_result = intent && (await load_route(intent));
278
280
 
279
281
  if (!navigation_result) {
282
+ if (is_external_url(url, base)) {
283
+ return await native_navigation(url);
284
+ }
280
285
  navigation_result = await server_fallback(
281
286
  url,
282
287
  { id: null },
@@ -1190,7 +1195,7 @@ export function create_client(app, target) {
1190
1195
  });
1191
1196
  }
1192
1197
 
1193
- if (__SVELTEKIT_DEV__) {
1198
+ if (DEV && status !== 404) {
1194
1199
  console.error(
1195
1200
  'An error occurred while loading the page. This will cause a full page reload. (This message will only appear during development.)'
1196
1201
  );
@@ -1270,7 +1275,7 @@ export function create_client(app, target) {
1270
1275
  if (priority <= options.preload_data) {
1271
1276
  const intent = get_navigation_intent(/** @type {URL} */ (url), false);
1272
1277
  if (intent) {
1273
- if (__SVELTEKIT_DEV__) {
1278
+ if (DEV) {
1274
1279
  preload_data(intent).then((result) => {
1275
1280
  if (result.type === 'loaded' && result.state.error) {
1276
1281
  console.warn(
@@ -1324,6 +1329,12 @@ export function create_client(app, target) {
1324
1329
  if (error instanceof HttpError) {
1325
1330
  return error.body;
1326
1331
  }
1332
+
1333
+ if (DEV) {
1334
+ errored = true;
1335
+ console.warn('The next HMR update will cause the page to reload');
1336
+ }
1337
+
1327
1338
  return (
1328
1339
  app.hooks.handleError({ error, event }) ??
1329
1340
  /** @type {any} */ ({ message: event.route.id != null ? 'Internal Error' : 'Not Found' })
@@ -1569,11 +1580,11 @@ export function create_client(app, target) {
1569
1580
  navigate({
1570
1581
  url,
1571
1582
  scroll: options.noscroll ? scroll_state() : null,
1572
- keepfocus: false,
1583
+ keepfocus: options.keep_focus ?? false,
1573
1584
  redirect_chain: [],
1574
1585
  details: {
1575
1586
  state: {},
1576
- replaceState: url.href === location.href
1587
+ replaceState: options.replace_state ?? url.href === location.href
1577
1588
  },
1578
1589
  accepted: () => event.preventDefault(),
1579
1590
  blocked: () => event.preventDefault(),
@@ -1604,7 +1615,7 @@ export function create_client(app, target) {
1604
1615
 
1605
1616
  const event_form = /** @type {HTMLFormElement} */ (event.target);
1606
1617
 
1607
- const { noscroll, reload } = get_router_options(event_form);
1618
+ const { keep_focus, noscroll, reload, replace_state } = get_router_options(event_form);
1608
1619
  if (reload) return;
1609
1620
 
1610
1621
  event.preventDefault();
@@ -1623,11 +1634,11 @@ export function create_client(app, target) {
1623
1634
  navigate({
1624
1635
  url,
1625
1636
  scroll: noscroll ? scroll_state() : null,
1626
- keepfocus: false,
1637
+ keepfocus: keep_focus ?? false,
1627
1638
  redirect_chain: [],
1628
1639
  details: {
1629
1640
  state: {},
1630
- replaceState: false
1641
+ replaceState: replace_state ?? url.href === location.href
1631
1642
  },
1632
1643
  nav_token: {},
1633
1644
  accepted: () => {},
@@ -1944,4 +1955,12 @@ if (DEV) {
1944
1955
  }
1945
1956
  console_warn(...args);
1946
1957
  };
1958
+
1959
+ if (import.meta.hot) {
1960
+ import.meta.hot.on('vite:beforeUpdate', () => {
1961
+ if (errored) {
1962
+ location.reload();
1963
+ }
1964
+ });
1965
+ }
1947
1966
  }
@@ -32,8 +32,10 @@ const warned = new WeakSet();
32
32
  const valid_link_options = /** @type {const} */ ({
33
33
  'preload-code': ['', 'off', 'tap', 'hover', 'viewport', 'eager'],
34
34
  'preload-data': ['', 'off', 'tap', 'hover'],
35
+ keepfocus: ['', 'off'],
35
36
  noscroll: ['', 'off'],
36
- reload: ['', 'off']
37
+ reload: ['', 'off'],
38
+ replacestate: ['', 'off']
37
39
  });
38
40
 
39
41
  /**
@@ -141,6 +143,9 @@ export function get_link_info(a, base) {
141
143
  * @param {HTMLFormElement | HTMLAnchorElement | SVGAElement} element
142
144
  */
143
145
  export function get_router_options(element) {
146
+ /** @type {ValidLinkOptions<'keepfocus'> | null} */
147
+ let keep_focus = null;
148
+
144
149
  /** @type {ValidLinkOptions<'noscroll'> | null} */
145
150
  let noscroll = null;
146
151
 
@@ -153,14 +158,19 @@ export function get_router_options(element) {
153
158
  /** @type {ValidLinkOptions<'reload'> | null} */
154
159
  let reload = null;
155
160
 
161
+ /** @type {ValidLinkOptions<'replacestate'> | null} */
162
+ let replace_state = null;
163
+
156
164
  /** @type {Element} */
157
165
  let el = element;
158
166
 
159
167
  while (el && el !== document.documentElement) {
160
168
  if (preload_code === null) preload_code = link_option(el, 'preload-code');
161
169
  if (preload_data === null) preload_data = link_option(el, 'preload-data');
170
+ if (keep_focus === null) keep_focus = link_option(el, 'keepfocus');
162
171
  if (noscroll === null) noscroll = link_option(el, 'noscroll');
163
172
  if (reload === null) reload = link_option(el, 'reload');
173
+ if (replace_state === null) replace_state = link_option(el, 'replacestate');
164
174
 
165
175
  el = /** @type {Element} */ (parent_element(el));
166
176
  }
@@ -168,8 +178,10 @@ export function get_router_options(element) {
168
178
  return {
169
179
  preload_code: levels[preload_code ?? 'off'],
170
180
  preload_data: levels[preload_data ?? 'off'],
181
+ keep_focus: keep_focus === 'off' ? false : keep_focus === '' ? true : null,
171
182
  noscroll: noscroll === 'off' ? false : noscroll === '' ? true : null,
172
- reload: reload === 'off' ? false : reload === '' ? true : null
183
+ reload: reload === 'off' ? false : reload === '' ? true : null,
184
+ replace_state: replace_state === 'off' ? false : replace_state === '' ? true : null
173
185
  };
174
186
  }
175
187
 
@@ -84,6 +84,7 @@ declare module '$app/forms' {
84
84
  form: HTMLFormElement;
85
85
  controller: AbortController;
86
86
  cancel(): void;
87
+ submitter: HTMLElement | null;
87
88
  }) => MaybePromise<
88
89
  | void
89
90
  | ((opts: {
package/types/index.d.ts CHANGED
@@ -87,7 +87,7 @@ export interface Builder {
87
87
  config: ValidatedConfig;
88
88
  /** Information about prerendered pages and assets, if any. */
89
89
  prerendered: Prerendered;
90
- /** An array of dynamic (not prerendered) routes */
90
+ /** An array of all routes (including prerendered) */
91
91
  routes: RouteDefinition[];
92
92
 
93
93
  /**