@sveltejs/kit 1.2.1 → 1.2.3
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 +3 -3
- package/src/core/env.js +1 -1
- package/src/core/postbuild/index.js +8 -1
- package/src/core/postbuild/prerender.js +2 -2
- package/src/core/sync/write_server.js +2 -2
- package/src/runtime/client/client.js +20 -8
- package/src/runtime/client/start.js +1 -2
- package/src/runtime/env/dynamic/private.js +1 -1
- package/src/runtime/env/dynamic/public.js +1 -1
- package/src/runtime/server/index.js +1 -2
- package/src/runtime/server/page/render.js +3 -4
- package/src/runtime/shared.js +16 -0
- package/types/internal.d.ts +2 -0
- package/src/runtime/env-private.js +0 -6
- package/src/runtime/env-public.js +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
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.15.
|
|
25
|
+
"undici": "5.15.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@playwright/test": "^1.29.2",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"format": "pnpm lint --write",
|
|
87
87
|
"test": "pnpm test:unit && pnpm test:integration",
|
|
88
88
|
"test:integration": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test",
|
|
89
|
-
"test:cross-
|
|
89
|
+
"test:cross-platform": "pnpm test:unit && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform",
|
|
90
90
|
"test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
|
|
91
91
|
"postinstall": "node postinstall.js"
|
|
92
92
|
}
|
package/src/core/env.js
CHANGED
|
@@ -44,7 +44,7 @@ export function create_dynamic_module(type, dev_values) {
|
|
|
44
44
|
);
|
|
45
45
|
return `export const env = {\n${keys.join(',\n')}\n}`;
|
|
46
46
|
}
|
|
47
|
-
return `export { env } from '${runtime_base}/
|
|
47
|
+
return `export { ${type}_env as env } from '${runtime_base}/shared.js';`;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -10,7 +10,8 @@ import {
|
|
|
10
10
|
import { load_config } from '../config/index.js';
|
|
11
11
|
import { prerender } from './prerender.js';
|
|
12
12
|
|
|
13
|
-
const [, , client_out_dir, manifest_path, results_path, verbose,
|
|
13
|
+
const [, , client_out_dir, manifest_path, results_path, verbose, env_json] = process.argv;
|
|
14
|
+
const env = JSON.parse(env_json);
|
|
14
15
|
|
|
15
16
|
/** @type {import('types').SSRManifest} */
|
|
16
17
|
const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;
|
|
@@ -33,6 +34,12 @@ const { Server } = await import(pathToFileURL(`${server_root}/server/index.js`).
|
|
|
33
34
|
// essential we do this before analysing the code
|
|
34
35
|
internal.set_building(true);
|
|
35
36
|
|
|
37
|
+
// set env, in case it's used in initialisation
|
|
38
|
+
const entries = Object.entries(env);
|
|
39
|
+
const prefix = config.env.publicPrefix;
|
|
40
|
+
internal.set_private_env(Object.fromEntries(entries.filter(([k]) => !k.startsWith(prefix))));
|
|
41
|
+
internal.set_public_env(Object.fromEntries(entries.filter(([k]) => k.startsWith(prefix))));
|
|
42
|
+
|
|
36
43
|
// analyse routes
|
|
37
44
|
for (const route of manifest._.routes) {
|
|
38
45
|
if (route.endpoint) {
|
|
@@ -50,7 +50,7 @@ const REDIRECT = 3;
|
|
|
50
50
|
* prerender_map: import('types').PrerenderMap;
|
|
51
51
|
* client_out_dir: string;
|
|
52
52
|
* verbose: string;
|
|
53
|
-
* env: string
|
|
53
|
+
* env: Record<string, string>;
|
|
54
54
|
* }} opts
|
|
55
55
|
* @returns
|
|
56
56
|
*/
|
|
@@ -92,7 +92,7 @@ export async function prerender({
|
|
|
92
92
|
internal.set_paths(config.paths);
|
|
93
93
|
|
|
94
94
|
const server = new Server(manifest);
|
|
95
|
-
await server.init({ env
|
|
95
|
+
await server.init({ env });
|
|
96
96
|
|
|
97
97
|
const handle_http_error = normalise_error_handler(
|
|
98
98
|
log,
|
|
@@ -24,7 +24,7 @@ const server_template = ({
|
|
|
24
24
|
error_page
|
|
25
25
|
}) => `
|
|
26
26
|
import root from './root.svelte';
|
|
27
|
-
import { set_building, set_paths, set_version } from '${runtime_directory}/shared.js';
|
|
27
|
+
import { set_building, set_paths, set_private_env, set_public_env, set_version } from '${runtime_directory}/shared.js';
|
|
28
28
|
|
|
29
29
|
set_paths(${s(config.kit.paths)});
|
|
30
30
|
set_version(${s(config.kit.version.name)});
|
|
@@ -57,7 +57,7 @@ export function get_hooks() {
|
|
|
57
57
|
return ${hooks ? `import(${s(hooks)})` : '{}'};
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export { set_building, set_paths };
|
|
60
|
+
export { set_building, set_paths, set_private_env, set_public_env };
|
|
61
61
|
`;
|
|
62
62
|
|
|
63
63
|
// TODO need to re-run this whenever src/app.html or src/error.html are
|
|
@@ -326,13 +326,22 @@ export function create_client({ target, base }) {
|
|
|
326
326
|
// opts must be passed if we're navigating
|
|
327
327
|
if (opts) {
|
|
328
328
|
const { scroll, keepfocus } = opts;
|
|
329
|
+
const { activeElement } = document;
|
|
329
330
|
|
|
330
|
-
//
|
|
331
|
-
if (!keepfocus) reset_focus();
|
|
332
|
-
|
|
333
|
-
// need to render the DOM before we can scroll to the rendered elements
|
|
331
|
+
// need to render the DOM before we can scroll to the rendered elements and do focus management
|
|
334
332
|
await tick();
|
|
335
333
|
|
|
334
|
+
const changed_focus =
|
|
335
|
+
// reset focus only if any manual focus management didn't override it
|
|
336
|
+
document.activeElement !== activeElement &&
|
|
337
|
+
// also refocus when activeElement is body already because the
|
|
338
|
+
// focus event might not have been fired on it yet
|
|
339
|
+
document.activeElement !== document.body;
|
|
340
|
+
|
|
341
|
+
if (!keepfocus && !changed_focus) {
|
|
342
|
+
await reset_focus();
|
|
343
|
+
}
|
|
344
|
+
|
|
336
345
|
if (autoscroll) {
|
|
337
346
|
const deep_linked = url.hash && document.getElementById(url.hash.slice(1));
|
|
338
347
|
if (scroll) {
|
|
@@ -1718,16 +1727,19 @@ function reset_focus() {
|
|
|
1718
1727
|
root.tabIndex = -1;
|
|
1719
1728
|
root.focus({ preventScroll: true });
|
|
1720
1729
|
|
|
1721
|
-
setTimeout(() => {
|
|
1722
|
-
getSelection()?.removeAllRanges();
|
|
1723
|
-
});
|
|
1724
|
-
|
|
1725
1730
|
// restore `tabindex` as to prevent `root` from stealing input from elements
|
|
1726
1731
|
if (tabindex !== null) {
|
|
1727
1732
|
root.setAttribute('tabindex', tabindex);
|
|
1728
1733
|
} else {
|
|
1729
1734
|
root.removeAttribute('tabindex');
|
|
1730
1735
|
}
|
|
1736
|
+
|
|
1737
|
+
return new Promise((resolve) => {
|
|
1738
|
+
setTimeout(() => {
|
|
1739
|
+
// fixes https://github.com/sveltejs/kit/issues/8439
|
|
1740
|
+
resolve(getSelection()?.removeAllRanges());
|
|
1741
|
+
});
|
|
1742
|
+
});
|
|
1731
1743
|
}
|
|
1732
1744
|
}
|
|
1733
1745
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { DEV } from 'esm-env';
|
|
2
2
|
import { create_client } from './client.js';
|
|
3
3
|
import { init } from './singletons.js';
|
|
4
|
-
import { set_paths, set_version } from '../shared.js';
|
|
5
|
-
import { set_public_env } from '../env-public.js';
|
|
4
|
+
import { set_paths, set_version, set_public_env } from '../shared.js';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* @param {{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { env } from '../../
|
|
1
|
+
export { private_env as env } from '../../shared.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { env } from '../../
|
|
1
|
+
export { public_env as env } from '../../shared.js';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { respond } from './respond.js';
|
|
2
|
-
import { set_private_env } from '../
|
|
3
|
-
import { set_public_env } from '../env-public.js';
|
|
2
|
+
import { set_private_env, set_public_env } from '../shared.js';
|
|
4
3
|
import { options, get_hooks } from '__GENERATED__/server-internal.js';
|
|
5
4
|
|
|
6
5
|
export class Server {
|
|
@@ -7,8 +7,7 @@ import { s } from '../../../utils/misc.js';
|
|
|
7
7
|
import { Csp } from './csp.js';
|
|
8
8
|
import { uneval_action_response } from './actions.js';
|
|
9
9
|
import { clarify_devalue_error } from '../utils.js';
|
|
10
|
-
import { assets, base, version } from '../../shared.js';
|
|
11
|
-
import { env } from '../../env-public.js';
|
|
10
|
+
import { assets, base, version, public_env } from '../../shared.js';
|
|
12
11
|
import { text } from '../../../exports/index.js';
|
|
13
12
|
|
|
14
13
|
// TODO rename this function/module
|
|
@@ -258,7 +257,7 @@ export async function render_response({
|
|
|
258
257
|
|
|
259
258
|
if (page_config.csr) {
|
|
260
259
|
const opts = [
|
|
261
|
-
`env: ${s(
|
|
260
|
+
`env: ${s(public_env)}`,
|
|
262
261
|
`paths: ${s({ assets, base })}`,
|
|
263
262
|
`target: document.querySelector('[data-sveltekit-hydrate="${target}"]').parentNode`,
|
|
264
263
|
`version: ${s(version)}`
|
|
@@ -368,7 +367,7 @@ export async function render_response({
|
|
|
368
367
|
body,
|
|
369
368
|
assets: resolved_assets,
|
|
370
369
|
nonce: /** @type {string} */ (csp.nonce),
|
|
371
|
-
env
|
|
370
|
+
env: public_env
|
|
372
371
|
});
|
|
373
372
|
|
|
374
373
|
// TODO flush chunks as early as we can
|
package/src/runtime/shared.js
CHANGED
|
@@ -3,6 +3,12 @@ export let base = '';
|
|
|
3
3
|
export let building = false;
|
|
4
4
|
export let version = '';
|
|
5
5
|
|
|
6
|
+
/** @type {Record<string, string>} */
|
|
7
|
+
export let private_env = {};
|
|
8
|
+
|
|
9
|
+
/** @type {Record<string, string>} */
|
|
10
|
+
export let public_env = {};
|
|
11
|
+
|
|
6
12
|
/** @param {string} stack */
|
|
7
13
|
export let fix_stack_trace = (stack) => stack;
|
|
8
14
|
|
|
@@ -17,6 +23,16 @@ export function set_building(value) {
|
|
|
17
23
|
building = value;
|
|
18
24
|
}
|
|
19
25
|
|
|
26
|
+
/** @type {(environment: Record<string, string>) => void} */
|
|
27
|
+
export function set_private_env(environment) {
|
|
28
|
+
private_env = environment;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** @type {(environment: Record<string, string>) => void} */
|
|
32
|
+
export function set_public_env(environment) {
|
|
33
|
+
public_env = environment;
|
|
34
|
+
}
|
|
35
|
+
|
|
20
36
|
/** @param {string} value */
|
|
21
37
|
export function set_version(value) {
|
|
22
38
|
version = value;
|
package/types/internal.d.ts
CHANGED
|
@@ -32,6 +32,8 @@ export interface ServerModule {
|
|
|
32
32
|
export interface ServerInternalModule {
|
|
33
33
|
set_building(building: boolean): void;
|
|
34
34
|
set_paths(paths: { base: string; assets: string }): void;
|
|
35
|
+
set_private_env(environment: Record<string, string>): void;
|
|
36
|
+
set_public_env(environment: Record<string, string>): void;
|
|
35
37
|
set_version(version: string): void;
|
|
36
38
|
set_fix_stack_trace(fix_stack_trace: (stack: string) => string): void;
|
|
37
39
|
}
|