solid-js 1.9.3 → 1.9.4

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/dist/dev.cjs CHANGED
@@ -275,14 +275,14 @@ function createResource(pSource, pFetcher, pOptions) {
275
275
  let source;
276
276
  let fetcher;
277
277
  let options;
278
- if (arguments.length === 2 && typeof pFetcher === "object" || arguments.length === 1) {
279
- source = true;
280
- fetcher = pSource;
281
- options = pFetcher || {};
282
- } else {
278
+ if (typeof pFetcher === "function") {
283
279
  source = pSource;
284
280
  fetcher = pFetcher;
285
281
  options = pOptions || {};
282
+ } else {
283
+ source = true;
284
+ fetcher = pSource;
285
+ options = pFetcher || {};
286
286
  }
287
287
  let pr = null,
288
288
  initP = NO_INIT,
package/dist/dev.js CHANGED
@@ -289,14 +289,14 @@ function createResource(pSource, pFetcher, pOptions) {
289
289
  let source;
290
290
  let fetcher;
291
291
  let options;
292
- if ((arguments.length === 2 && typeof pFetcher === "object") || arguments.length === 1) {
293
- source = true;
294
- fetcher = pSource;
295
- options = pFetcher || {};
296
- } else {
292
+ if (typeof pFetcher === "function") {
297
293
  source = pSource;
298
294
  fetcher = pFetcher;
299
295
  options = pOptions || {};
296
+ } else {
297
+ source = true;
298
+ fetcher = pSource;
299
+ options = pFetcher || {};
300
300
  }
301
301
  let pr = null,
302
302
  initP = NO_INIT,
package/dist/server.cjs CHANGED
@@ -302,6 +302,51 @@ function mutateContext(o, key, value) {
302
302
  }
303
303
  }
304
304
 
305
+ function escape(s, attr) {
306
+ const t = typeof s;
307
+ if (t !== "string") {
308
+ if (t === "function") return escape(s());
309
+ if (Array.isArray(s)) {
310
+ for (let i = 0; i < s.length; i++) s[i] = escape(s[i]);
311
+ return s;
312
+ }
313
+ return s;
314
+ }
315
+ const delim = "<";
316
+ const escDelim = "&lt;";
317
+ let iDelim = s.indexOf(delim);
318
+ let iAmp = s.indexOf("&");
319
+ if (iDelim < 0 && iAmp < 0) return s;
320
+ let left = 0,
321
+ out = "";
322
+ while (iDelim >= 0 && iAmp >= 0) {
323
+ if (iDelim < iAmp) {
324
+ if (left < iDelim) out += s.substring(left, iDelim);
325
+ out += escDelim;
326
+ left = iDelim + 1;
327
+ iDelim = s.indexOf(delim, left);
328
+ } else {
329
+ if (left < iAmp) out += s.substring(left, iAmp);
330
+ out += "&amp;";
331
+ left = iAmp + 1;
332
+ iAmp = s.indexOf("&", left);
333
+ }
334
+ }
335
+ if (iDelim >= 0) {
336
+ do {
337
+ if (left < iDelim) out += s.substring(left, iDelim);
338
+ out += escDelim;
339
+ left = iDelim + 1;
340
+ iDelim = s.indexOf(delim, left);
341
+ } while (iDelim >= 0);
342
+ } else while (iAmp >= 0) {
343
+ if (left < iAmp) out += s.substring(left, iAmp);
344
+ out += "&amp;";
345
+ left = iAmp + 1;
346
+ iAmp = s.indexOf("&", left);
347
+ }
348
+ return left < s.length ? out + s.substring(left) : out;
349
+ }
305
350
  function resolveSSRNode(node) {
306
351
  const t = typeof node;
307
352
  if (t === "string") return node;
@@ -464,19 +509,14 @@ function ErrorBoundary(props) {
464
509
  if (error) return displayFallback();
465
510
  sync = false;
466
511
  return {
467
- t: `<!--!$e${id}-->${resolveSSRNode(res)}<!--!$/e${id}-->`
512
+ t: `<!--!$e${id}-->${resolveSSRNode(escape(res))}<!--!$/e${id}-->`
468
513
  };
469
514
  }
470
515
  const SuspenseContext = createContext();
471
516
  let resourceContext = null;
472
517
  function createResource(source, fetcher, options = {}) {
473
- if (arguments.length === 2) {
474
- if (typeof fetcher === "object") {
475
- options = fetcher;
476
- fetcher = source;
477
- source = true;
478
- }
479
- } else if (arguments.length === 1) {
518
+ if (typeof fetcher !== "function") {
519
+ options = fetcher || {};
480
520
  fetcher = source;
481
521
  source = true;
482
522
  }
@@ -641,7 +681,7 @@ function Suspense(props) {
641
681
  completed: () => {
642
682
  const res = runSuspense();
643
683
  if (suspenseComplete(value)) {
644
- done(resolveSSRNode(res));
684
+ done(resolveSSRNode(escape(res)));
645
685
  }
646
686
  }
647
687
  });
@@ -680,7 +720,7 @@ function Suspense(props) {
680
720
  noHydrate: true
681
721
  });
682
722
  const res = {
683
- t: `<template id="pl-${id}"></template>${resolveSSRNode(props.fallback)}<!--pl-${id}-->`
723
+ t: `<template id="pl-${id}"></template>${resolveSSRNode(escape(props.fallback))}<!--pl-${id}-->`
684
724
  };
685
725
  setHydrateContext(ctx);
686
726
  return res;
package/dist/server.js CHANGED
@@ -311,6 +311,52 @@ function mutateContext(o, key, value) {
311
311
  }
312
312
  }
313
313
 
314
+ function escape(s, attr) {
315
+ const t = typeof s;
316
+ if (t !== "string") {
317
+ if (t === "function") return escape(s());
318
+ if (Array.isArray(s)) {
319
+ for (let i = 0; i < s.length; i++) s[i] = escape(s[i]);
320
+ return s;
321
+ }
322
+ return s;
323
+ }
324
+ const delim = "<";
325
+ const escDelim = "&lt;";
326
+ let iDelim = s.indexOf(delim);
327
+ let iAmp = s.indexOf("&");
328
+ if (iDelim < 0 && iAmp < 0) return s;
329
+ let left = 0,
330
+ out = "";
331
+ while (iDelim >= 0 && iAmp >= 0) {
332
+ if (iDelim < iAmp) {
333
+ if (left < iDelim) out += s.substring(left, iDelim);
334
+ out += escDelim;
335
+ left = iDelim + 1;
336
+ iDelim = s.indexOf(delim, left);
337
+ } else {
338
+ if (left < iAmp) out += s.substring(left, iAmp);
339
+ out += "&amp;";
340
+ left = iAmp + 1;
341
+ iAmp = s.indexOf("&", left);
342
+ }
343
+ }
344
+ if (iDelim >= 0) {
345
+ do {
346
+ if (left < iDelim) out += s.substring(left, iDelim);
347
+ out += escDelim;
348
+ left = iDelim + 1;
349
+ iDelim = s.indexOf(delim, left);
350
+ } while (iDelim >= 0);
351
+ } else
352
+ while (iAmp >= 0) {
353
+ if (left < iAmp) out += s.substring(left, iAmp);
354
+ out += "&amp;";
355
+ left = iAmp + 1;
356
+ iAmp = s.indexOf("&", left);
357
+ }
358
+ return left < s.length ? out + s.substring(left) : out;
359
+ }
314
360
  function resolveSSRNode(node) {
315
361
  const t = typeof node;
316
362
  if (t === "string") return node;
@@ -483,19 +529,14 @@ function ErrorBoundary(props) {
483
529
  if (error) return displayFallback();
484
530
  sync = false;
485
531
  return {
486
- t: `<!--!$e${id}-->${resolveSSRNode(res)}<!--!$/e${id}-->`
532
+ t: `<!--!$e${id}-->${resolveSSRNode(escape(res))}<!--!$/e${id}-->`
487
533
  };
488
534
  }
489
535
  const SuspenseContext = createContext();
490
536
  let resourceContext = null;
491
537
  function createResource(source, fetcher, options = {}) {
492
- if (arguments.length === 2) {
493
- if (typeof fetcher === "object") {
494
- options = fetcher;
495
- fetcher = source;
496
- source = true;
497
- }
498
- } else if (arguments.length === 1) {
538
+ if (typeof fetcher !== "function") {
539
+ options = fetcher || {};
499
540
  fetcher = source;
500
541
  source = true;
501
542
  }
@@ -677,7 +718,7 @@ function Suspense(props) {
677
718
  completed: () => {
678
719
  const res = runSuspense();
679
720
  if (suspenseComplete(value)) {
680
- done(resolveSSRNode(res));
721
+ done(resolveSSRNode(escape(res)));
681
722
  }
682
723
  }
683
724
  });
@@ -718,7 +759,9 @@ function Suspense(props) {
718
759
  noHydrate: true
719
760
  });
720
761
  const res = {
721
- t: `<template id="pl-${id}"></template>${resolveSSRNode(props.fallback)}<!--pl-${id}-->`
762
+ t: `<template id="pl-${id}"></template>${resolveSSRNode(
763
+ escape(props.fallback)
764
+ )}<!--pl-${id}-->`
722
765
  };
723
766
  setHydrateContext(ctx);
724
767
  return res;
package/dist/solid.cjs CHANGED
@@ -257,14 +257,14 @@ function createResource(pSource, pFetcher, pOptions) {
257
257
  let source;
258
258
  let fetcher;
259
259
  let options;
260
- if (arguments.length === 2 && typeof pFetcher === "object" || arguments.length === 1) {
261
- source = true;
262
- fetcher = pSource;
263
- options = pFetcher || {};
264
- } else {
260
+ if (typeof pFetcher === "function") {
265
261
  source = pSource;
266
262
  fetcher = pFetcher;
267
263
  options = pOptions || {};
264
+ } else {
265
+ source = true;
266
+ fetcher = pSource;
267
+ options = pFetcher || {};
268
268
  }
269
269
  let pr = null,
270
270
  initP = NO_INIT,
package/dist/solid.js CHANGED
@@ -267,14 +267,14 @@ function createResource(pSource, pFetcher, pOptions) {
267
267
  let source;
268
268
  let fetcher;
269
269
  let options;
270
- if ((arguments.length === 2 && typeof pFetcher === "object") || arguments.length === 1) {
271
- source = true;
272
- fetcher = pSource;
273
- options = pFetcher || {};
274
- } else {
270
+ if (typeof pFetcher === "function") {
275
271
  source = pSource;
276
272
  fetcher = pFetcher;
277
273
  options = pOptions || {};
274
+ } else {
275
+ source = true;
276
+ fetcher = pSource;
277
+ options = pFetcher || {};
278
278
  }
279
279
  let pr = null,
280
280
  initP = NO_INIT,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solid-js",
3
3
  "description": "A declarative JavaScript library for building user interfaces.",
4
- "version": "1.9.3",
4
+ "version": "1.9.4",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -341,7 +341,7 @@ function applyState(target, parent, property, merge, key) {
341
341
  }
342
342
  const temp = new Array(target.length),
343
343
  newIndices = new Map();
344
- for (end = previous.length - 1, newEnd = target.length - 1; end >= start && newEnd >= start && (previous[end] === target[newEnd] || key && previous[start] && target[start] && previous[end][key] === target[newEnd][key]); end--, newEnd--) {
344
+ for (end = previous.length - 1, newEnd = target.length - 1; end >= start && newEnd >= start && (previous[end] === target[newEnd] || key && previous[end] && target[newEnd] && previous[end][key] === target[newEnd][key]); end--, newEnd--) {
345
345
  temp[newEnd] = previous[end];
346
346
  }
347
347
  if (start > newEnd || start > end) {
package/store/dist/dev.js CHANGED
@@ -411,7 +411,7 @@ function applyState(target, parent, property, merge, key) {
411
411
  end >= start &&
412
412
  newEnd >= start &&
413
413
  (previous[end] === target[newEnd] ||
414
- (key && previous[start] && target[start] && previous[end][key] === target[newEnd][key]));
414
+ (key && previous[end] && target[newEnd] && previous[end][key] === target[newEnd][key]));
415
415
  end--, newEnd--
416
416
  ) {
417
417
  temp[newEnd] = previous[end];
@@ -325,7 +325,7 @@ function applyState(target, parent, property, merge, key) {
325
325
  }
326
326
  const temp = new Array(target.length),
327
327
  newIndices = new Map();
328
- for (end = previous.length - 1, newEnd = target.length - 1; end >= start && newEnd >= start && (previous[end] === target[newEnd] || key && previous[start] && target[start] && previous[end][key] === target[newEnd][key]); end--, newEnd--) {
328
+ for (end = previous.length - 1, newEnd = target.length - 1; end >= start && newEnd >= start && (previous[end] === target[newEnd] || key && previous[end] && target[newEnd] && previous[end][key] === target[newEnd][key]); end--, newEnd--) {
329
329
  temp[newEnd] = previous[end];
330
330
  }
331
331
  if (start > newEnd || start > end) {
@@ -389,7 +389,7 @@ function applyState(target, parent, property, merge, key) {
389
389
  end >= start &&
390
390
  newEnd >= start &&
391
391
  (previous[end] === target[newEnd] ||
392
- (key && previous[start] && target[start] && previous[end][key] === target[newEnd][key]));
392
+ (key && previous[end] && target[newEnd] && previous[end][key] === target[newEnd][key]));
393
393
  end--, newEnd--
394
394
  ) {
395
395
  temp[newEnd] = previous[end];
@@ -217,7 +217,7 @@ function renderToStream(code, options = {}) {
217
217
  const first = html.indexOf(placeholder);
218
218
  if (first === -1) return;
219
219
  const last = html.indexOf(`<!--!$/${id}-->`, first + placeholder.length);
220
- html = html.replace(html.slice(first, last + placeholder.length + 1), resolveSSRNode(payloadFn()));
220
+ html = html.slice(0, first) + resolveSSRNode(escape(payloadFn())) + html.slice(last + placeholder.length + 1);
221
221
  },
222
222
  serialize(id, p, wait) {
223
223
  const serverOnly = solidJs.sharedConfig.context.noHydrate;
@@ -516,7 +516,7 @@ function getHydrationKey() {
516
516
  return hydrate && !hydrate.noHydrate && solidJs.sharedConfig.getNextContextId();
517
517
  }
518
518
  function useAssets(fn) {
519
- solidJs.sharedConfig.context.assets.push(() => resolveSSRNode(fn()));
519
+ solidJs.sharedConfig.context.assets.push(() => resolveSSRNode(escape(fn())));
520
520
  }
521
521
  function getAssets() {
522
522
  const assets = solidJs.sharedConfig.context.assets;
@@ -561,7 +561,9 @@ function injectAssets(assets, html) {
561
561
  if (!assets || !assets.length) return html;
562
562
  let out = "";
563
563
  for (let i = 0, len = assets.length; i < len; i++) out += assets[i]();
564
- return html.replace(`</head>`, out + `</head>`);
564
+ const index = html.indexOf("</head>");
565
+ if (index === -1) return html;
566
+ return html.slice(0, index) + out + html.slice(index);
565
567
  }
566
568
  function injectScripts(html, scripts, nonce) {
567
569
  const tag = `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>`;
@@ -654,10 +654,10 @@ function renderToStream(code, options = {}) {
654
654
  const first = html.indexOf(placeholder);
655
655
  if (first === -1) return;
656
656
  const last = html.indexOf(`<!--!$/${id}-->`, first + placeholder.length);
657
- html = html.replace(
658
- html.slice(first, last + placeholder.length + 1),
659
- resolveSSRNode(payloadFn())
660
- );
657
+ html =
658
+ html.slice(0, first) +
659
+ resolveSSRNode(escape(payloadFn())) +
660
+ html.slice(last + placeholder.length + 1);
661
661
  },
662
662
  serialize(id, p, wait) {
663
663
  const serverOnly = sharedConfig.context.noHydrate;
@@ -977,7 +977,7 @@ function getHydrationKey() {
977
977
  return hydrate && !hydrate.noHydrate && sharedConfig.getNextContextId();
978
978
  }
979
979
  function useAssets(fn) {
980
- sharedConfig.context.assets.push(() => resolveSSRNode(fn()));
980
+ sharedConfig.context.assets.push(() => resolveSSRNode(escape(fn())));
981
981
  }
982
982
  function getAssets() {
983
983
  const assets = sharedConfig.context.assets;
@@ -1023,7 +1023,9 @@ function injectAssets(assets, html) {
1023
1023
  if (!assets || !assets.length) return html;
1024
1024
  let out = "";
1025
1025
  for (let i = 0, len = assets.length; i < len; i++) out += assets[i]();
1026
- return html.replace(`</head>`, out + `</head>`);
1026
+ const index = html.indexOf("</head>");
1027
+ if (index === -1) return html;
1028
+ return html.slice(0, index) + out + html.slice(index);
1027
1029
  }
1028
1030
  function injectScripts(html, scripts, nonce) {
1029
1031
  const tag = `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>`;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.provideRequestEvent = void 0;
4
- var node_async_hooks_1 = require("node:async_hooks");
5
- var web_1 = require("solid-js/web");
6
- // using global on a symbol for locating it later and detaching for environments that don't support it.
7
- function provideRequestEvent(init, cb) {
8
- if (!web_1.isServer) throw new Error("Attempting to use server context in non-server build");
9
- var ctx = (globalThis[web_1.RequestContext] =
10
- globalThis[web_1.RequestContext] || new node_async_hooks_1.AsyncLocalStorage());
11
- return ctx.run(init, cb);
12
- }
13
- exports.provideRequestEvent = provideRequestEvent;