@sveltejs/kit 1.2.8 → 1.2.10
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
|
@@ -315,17 +315,30 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
315
315
|
}
|
|
316
316
|
});
|
|
317
317
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
318
|
+
async function align_exports() {
|
|
319
|
+
// This shameful hack allows us to load runtime server code via Vite
|
|
320
|
+
// while apps load `HttpError` and `Redirect` in Node, without
|
|
321
|
+
// causing `instanceof` checks to fail
|
|
322
|
+
const control_module_node = await import(`../../../runtime/control.js`);
|
|
323
|
+
const control_module_vite = await vite.ssrLoadModule(`${runtime_base}/control.js`);
|
|
324
|
+
|
|
325
|
+
control_module_node.replace_implementations({
|
|
326
|
+
ActionFailure: control_module_vite.ActionFailure,
|
|
327
|
+
HttpError: control_module_vite.HttpError,
|
|
328
|
+
Redirect: control_module_vite.Redirect
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
align_exports();
|
|
332
|
+
const ws_send = vite.ws.send;
|
|
333
|
+
/** @param {any} args */
|
|
334
|
+
vite.ws.send = function (...args) {
|
|
335
|
+
// We need to reapply the patch after Vite did dependency optimizations
|
|
336
|
+
// because that clears the module resolutions
|
|
337
|
+
if (args[0]?.type === 'full-reload' && args[0].path === '*') {
|
|
338
|
+
align_exports();
|
|
339
|
+
}
|
|
340
|
+
return ws_send.apply(vite.ws, args);
|
|
341
|
+
};
|
|
329
342
|
|
|
330
343
|
vite.middlewares.use(async (req, res, next) => {
|
|
331
344
|
try {
|
|
@@ -69,23 +69,23 @@ export async function handle_action_json_request(event, options, server) {
|
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
} catch (e) {
|
|
72
|
-
const
|
|
72
|
+
const err = normalize_error(e);
|
|
73
73
|
|
|
74
|
-
if (
|
|
74
|
+
if (err instanceof Redirect) {
|
|
75
75
|
return action_json({
|
|
76
76
|
type: 'redirect',
|
|
77
|
-
status:
|
|
78
|
-
location:
|
|
77
|
+
status: err.status,
|
|
78
|
+
location: err.location
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
return action_json(
|
|
83
83
|
{
|
|
84
84
|
type: 'error',
|
|
85
|
-
error: await handle_error_and_jsonify(event, options, check_incorrect_fail_use(
|
|
85
|
+
error: await handle_error_and_jsonify(event, options, check_incorrect_fail_use(err))
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
|
-
status:
|
|
88
|
+
status: err instanceof HttpError ? err.status : 500
|
|
89
89
|
}
|
|
90
90
|
);
|
|
91
91
|
}
|
|
@@ -110,19 +110,18 @@ function action_json(data, init) {
|
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
112
|
* @param {import('types').RequestEvent} event
|
|
113
|
-
* @param {import('types').SSRNode} leaf_node
|
|
114
113
|
*/
|
|
115
|
-
export function is_action_request(event
|
|
116
|
-
return
|
|
114
|
+
export function is_action_request(event) {
|
|
115
|
+
return event.request.method === 'POST';
|
|
117
116
|
}
|
|
118
117
|
|
|
119
118
|
/**
|
|
120
119
|
* @param {import('types').RequestEvent} event
|
|
121
|
-
* @param {import('types').SSRNode['server']} server
|
|
120
|
+
* @param {import('types').SSRNode['server'] | undefined} server
|
|
122
121
|
* @returns {Promise<import('types').ActionResult>}
|
|
123
122
|
*/
|
|
124
123
|
export async function handle_action_request(event, server) {
|
|
125
|
-
const actions = server
|
|
124
|
+
const actions = server?.actions;
|
|
126
125
|
|
|
127
126
|
if (!actions) {
|
|
128
127
|
// TODO should this be a different error altogether?
|
|
@@ -161,19 +160,19 @@ export async function handle_action_request(event, server) {
|
|
|
161
160
|
};
|
|
162
161
|
}
|
|
163
162
|
} catch (e) {
|
|
164
|
-
const
|
|
163
|
+
const err = normalize_error(e);
|
|
165
164
|
|
|
166
|
-
if (
|
|
165
|
+
if (err instanceof Redirect) {
|
|
167
166
|
return {
|
|
168
167
|
type: 'redirect',
|
|
169
|
-
status:
|
|
170
|
-
location:
|
|
168
|
+
status: err.status,
|
|
169
|
+
location: err.location
|
|
171
170
|
};
|
|
172
171
|
}
|
|
173
172
|
|
|
174
173
|
return {
|
|
175
174
|
type: 'error',
|
|
176
|
-
error: check_incorrect_fail_use(
|
|
175
|
+
error: check_incorrect_fail_use(err)
|
|
177
176
|
};
|
|
178
177
|
}
|
|
179
178
|
}
|
|
@@ -59,7 +59,7 @@ export async function render_page(event, route, page, options, manifest, state,
|
|
|
59
59
|
/** @type {import('types').ActionResult | undefined} */
|
|
60
60
|
let action_result = undefined;
|
|
61
61
|
|
|
62
|
-
if (is_action_request(event
|
|
62
|
+
if (is_action_request(event)) {
|
|
63
63
|
// for action requests, first call handler in +page.server.js
|
|
64
64
|
// (this also determines status code)
|
|
65
65
|
action_result = await handle_action_request(event, leaf_node.server);
|
|
@@ -85,7 +85,7 @@ export async function render_page(event, route, page, options, manifest, state,
|
|
|
85
85
|
|
|
86
86
|
if (should_prerender) {
|
|
87
87
|
const mod = leaf_node.server;
|
|
88
|
-
if (mod
|
|
88
|
+
if (mod?.actions) {
|
|
89
89
|
throw new Error('Cannot prerender pages with actions');
|
|
90
90
|
}
|
|
91
91
|
} else if (state.prerendering) {
|