@solidjs/start 1.0.10 → 1.0.11

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.
@@ -5,7 +5,7 @@ import { CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, Hea
5
5
  import { sharedConfig } from "solid-js";
6
6
  import { renderToString } from "solid-js/web";
7
7
  import { provideRequestEvent } from "solid-js/web/storage";
8
- import { eventHandler, setHeader, setResponseStatus } from "vinxi/http";
8
+ import { eventHandler, parseCookies, setHeader, setResponseStatus } from "vinxi/http";
9
9
  import invariant from "vinxi/lib/invariant";
10
10
  import { cloneEvent, getFetchEvent, mergeResponseHeaders } from "../server/fetchEvent";
11
11
  import { getExpectedRedirectStatus } from "../server/handler";
@@ -100,12 +100,13 @@ async function handleServerFunction(h3Event) {
100
100
  // This should never be the case in "proper" Nitro presets since node.req has to be IncomingMessage,
101
101
  // But the new azure-functions preset for some reason uses a ReadableStream in node.req (#1521)
102
102
  const isReadableStream = h3Request instanceof ReadableStream;
103
- const isH3EventBodyStreamLocked = isReadableStream && h3Request.locked;
103
+ const hasReadableStream = h3Request.body instanceof ReadableStream;
104
+ const isH3EventBodyStreamLocked = (isReadableStream && h3Request.locked) || (hasReadableStream && h3Request.body.locked);
104
105
  const requestBody = isReadableStream ? h3Request : h3Request.body;
105
106
  if (contentType?.startsWith("multipart/form-data") ||
106
107
  contentType?.startsWith("application/x-www-form-urlencoded")) {
107
108
  // workaround for https://github.com/unjs/nitro/issues/1721
108
- // (issue only in edge runtimes)
109
+ // (issue only in edge runtimes and netlify preset)
109
110
  parsed.push(await (isH3EventBodyStreamLocked
110
111
  ? request
111
112
  : new Request(request, { ...request, body: requestBody })).formData());
@@ -114,7 +115,7 @@ async function handleServerFunction(h3Event) {
114
115
  }
115
116
  else if (contentType?.startsWith("application/json")) {
116
117
  // workaround for https://github.com/unjs/nitro/issues/1721
117
- // (issue only in edge runtimes)
118
+ // (issue only in edge runtimes and netlify preset)
118
119
  const tmpReq = isH3EventBodyStreamLocked
119
120
  ? request
120
121
  : new Request(request, { ...request, body: requestBody });
@@ -233,6 +234,32 @@ function handleNoJS(result, request, parsed, thrown) {
233
234
  });
234
235
  }
235
236
  let App;
237
+ function createSingleFlightHeaders(sourceEvent) {
238
+ // cookie handling logic is pretty simplistic so this might be imperfect
239
+ // unclear if h3 internals are available on all platforms but we need a way to
240
+ // update request headers on the underlying H3 event.
241
+ const headers = new Headers(sourceEvent.request.headers);
242
+ const cookies = parseCookies(sourceEvent.nativeEvent);
243
+ const SetCookies = sourceEvent.response.headers.getSetCookie();
244
+ headers.delete("cookie");
245
+ let useH3Internals = false;
246
+ if (sourceEvent.nativeEvent.node?.req) {
247
+ useH3Internals = true;
248
+ sourceEvent.nativeEvent.node.req.headers.cookie = "";
249
+ }
250
+ SetCookies.forEach((cookie) => {
251
+ if (!cookie)
252
+ return;
253
+ const keyValue = cookie.split(";")[0];
254
+ const [key, value] = keyValue.split("=");
255
+ key && value && (cookies[key] = value);
256
+ });
257
+ Object.entries(cookies).forEach(([key, value]) => {
258
+ headers.append("cookie", `${key}=${value}`);
259
+ useH3Internals && (sourceEvent.nativeEvent.node.req.headers.cookie += `${key}=${value};`);
260
+ });
261
+ return headers;
262
+ }
236
263
  async function handleSingleFlight(sourceEvent, result) {
237
264
  let revalidate;
238
265
  let url = new URL(sourceEvent.request.headers.get("referer")).toString();
@@ -243,7 +270,7 @@ async function handleSingleFlight(sourceEvent, result) {
243
270
  url = new URL(result.headers.get("Location"), new URL(sourceEvent.request.url).origin + import.meta.env.SERVER_BASE_URL).toString();
244
271
  }
245
272
  const event = cloneEvent(sourceEvent);
246
- event.request = new Request(url, { headers: sourceEvent.request.headers });
273
+ event.request = new Request(url, { headers: createSingleFlightHeaders(sourceEvent) });
247
274
  return await provideRequestEvent(event, async () => {
248
275
  await createPageEvent(event);
249
276
  /* @ts-ignore */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/start",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "type": "module",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
@@ -73,7 +73,7 @@
73
73
  "source-map-js": "^1.0.2",
74
74
  "terracotta": "^1.0.4",
75
75
  "tinyglobby": "^0.2.2",
76
- "vite-plugin-solid": "^2.10.2"
76
+ "vite-plugin-solid": "^2.11.0"
77
77
  },
78
78
  "scripts": {
79
79
  "typecheck": "tsc --noEmit",