solid-js 1.9.3 → 1.9.5

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/web/dist/dev.cjs CHANGED
@@ -122,13 +122,13 @@ function render(code, element, init, options = {}) {
122
122
  element.textContent = "";
123
123
  };
124
124
  }
125
- function template(html, isImportNode, isSVG) {
125
+ function template(html, isImportNode, isSVG, isMathML) {
126
126
  let node;
127
127
  const create = () => {
128
128
  if (isHydrating()) throw new Error("Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration.");
129
- const t = document.createElement("template");
129
+ const t = isMathML ? document.createElementNS("http://www.w3.org/1998/Math/MathML", "template") : document.createElement("template");
130
130
  t.innerHTML = html;
131
- return isSVG ? t.content.firstChild.firstChild : t.content.firstChild;
131
+ return isSVG ? t.content.firstChild.firstChild : isMathML ? t.firstChild : t.content.firstChild;
132
132
  };
133
133
  const fn = isImportNode ? () => solidJs.untrack(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true);
134
134
  fn.cloneNode = fn;
@@ -385,7 +385,7 @@ function assignProp(node, prop, value, prev, isSVG, skipRef, props) {
385
385
  setAttribute(node, prop.slice(5), value);
386
386
  } else if (prop.slice(0, 5) === "bool:") {
387
387
  setBoolAttribute(node, prop.slice(5), value);
388
- } else if ((forceProp = prop.slice(0, 5) === "prop:") || (isChildProp = ChildProperties.has(prop)) || !isSVG && ((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-") || 'is' in props)) {
388
+ } else if ((forceProp = prop.slice(0, 5) === "prop:") || (isChildProp = ChildProperties.has(prop)) || !isSVG && ((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-") || "is" in props)) {
389
389
  if (forceProp) {
390
390
  prop = prop.slice(5);
391
391
  isProp = true;
@@ -669,9 +669,8 @@ function Portal(props) {
669
669
  });
670
670
  return marker;
671
671
  }
672
- function Dynamic(props) {
673
- const [p, others] = solidJs.splitProps(props, ["component"]);
674
- const cached = solidJs.createMemo(() => p.component);
672
+ function createDynamic(component, props) {
673
+ const cached = solidJs.createMemo(component);
675
674
  return solidJs.createMemo(() => {
676
675
  const component = cached();
677
676
  switch (typeof component) {
@@ -679,15 +678,19 @@ function Dynamic(props) {
679
678
  Object.assign(component, {
680
679
  [solidJs.$DEVCOMP]: true
681
680
  });
682
- return solidJs.untrack(() => component(others));
681
+ return solidJs.untrack(() => component(props));
683
682
  case "string":
684
683
  const isSvg = SVGElements.has(component);
685
684
  const el = solidJs.sharedConfig.context ? getNextElement() : createElement(component, isSvg);
686
- spread(el, others, isSvg);
685
+ spread(el, props, isSvg);
687
686
  return el;
688
687
  }
689
688
  });
690
689
  }
690
+ function Dynamic(props) {
691
+ const [, others] = solidJs.splitProps(props, ["component"]);
692
+ return createDynamic(() => props.component, others);
693
+ }
691
694
 
692
695
  Object.defineProperty(exports, "ErrorBoundary", {
693
696
  enumerable: true,
@@ -764,6 +767,7 @@ exports.assign = assign;
764
767
  exports.classList = classList;
765
768
  exports.className = className;
766
769
  exports.clearDelegatedEvents = clearDelegatedEvents;
770
+ exports.createDynamic = createDynamic;
767
771
  exports.delegateEvents = delegateEvents;
768
772
  exports.dynamicProperty = dynamicProperty;
769
773
  exports.escape = escape;
package/web/dist/dev.js CHANGED
@@ -10,8 +10,8 @@ import {
10
10
  createMemo,
11
11
  createSignal,
12
12
  onCleanup,
13
- splitProps,
14
- $DEVCOMP
13
+ $DEVCOMP,
14
+ splitProps
15
15
  } from "solid-js";
16
16
  export {
17
17
  ErrorBoundary,
@@ -571,16 +571,18 @@ function render(code, element, init, options = {}) {
571
571
  element.textContent = "";
572
572
  };
573
573
  }
574
- function template(html, isImportNode, isSVG) {
574
+ function template(html, isImportNode, isSVG, isMathML) {
575
575
  let node;
576
576
  const create = () => {
577
577
  if (isHydrating())
578
578
  throw new Error(
579
579
  "Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration."
580
580
  );
581
- const t = document.createElement("template");
581
+ const t = isMathML
582
+ ? document.createElementNS("http://www.w3.org/1998/Math/MathML", "template")
583
+ : document.createElement("template");
582
584
  t.innerHTML = html;
583
- return isSVG ? t.content.firstChild.firstChild : t.content.firstChild;
585
+ return isSVG ? t.content.firstChild.firstChild : isMathML ? t.firstChild : t.content.firstChild;
584
586
  };
585
587
  const fn = isImportNode
586
588
  ? () => untrack(() => document.importNode(node || (node = create()), true))
@@ -1160,9 +1162,8 @@ function Portal(props) {
1160
1162
  );
1161
1163
  return marker;
1162
1164
  }
1163
- function Dynamic(props) {
1164
- const [p, others] = splitProps(props, ["component"]);
1165
- const cached = createMemo(() => p.component);
1165
+ function createDynamic(component, props) {
1166
+ const cached = createMemo(component);
1166
1167
  return createMemo(() => {
1167
1168
  const component = cached();
1168
1169
  switch (typeof component) {
@@ -1170,15 +1171,19 @@ function Dynamic(props) {
1170
1171
  Object.assign(component, {
1171
1172
  [$DEVCOMP]: true
1172
1173
  });
1173
- return untrack(() => component(others));
1174
+ return untrack(() => component(props));
1174
1175
  case "string":
1175
1176
  const isSvg = SVGElements.has(component);
1176
1177
  const el = sharedConfig.context ? getNextElement() : createElement(component, isSvg);
1177
- spread(el, others, isSvg);
1178
+ spread(el, props, isSvg);
1178
1179
  return el;
1179
1180
  }
1180
1181
  });
1181
1182
  }
1183
+ function Dynamic(props) {
1184
+ const [, others] = splitProps(props, ["component"]);
1185
+ return createDynamic(() => props.component, others);
1186
+ }
1182
1187
 
1183
1188
  export {
1184
1189
  Aliases,
@@ -1200,6 +1205,7 @@ export {
1200
1205
  classList,
1201
1206
  className,
1202
1207
  clearDelegatedEvents,
1208
+ createDynamic,
1203
1209
  delegateEvents,
1204
1210
  dynamicProperty,
1205
1211
  escape,
@@ -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;
@@ -408,7 +408,7 @@ function ssrElement(tag, props, children, needsId) {
408
408
  for (let i = 0; i < keys.length; i++) {
409
409
  const prop = keys[i];
410
410
  if (ChildProperties.has(prop)) {
411
- if (children === undefined && !skipChildren) children = prop === "innerHTML" ? props[prop] : escape(props[prop]);
411
+ if (children === undefined && !skipChildren) children = tag === "script" || tag === "style" || prop === "innerHTML" ? props[prop] : escape(props[prop]);
412
412
  continue;
413
413
  }
414
414
  const value = props[prop];
@@ -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>`;
@@ -666,16 +668,19 @@ function notSup() {
666
668
 
667
669
  const isServer = true;
668
670
  const isDev = false;
669
- function Dynamic(props) {
670
- const [p, others] = solidJs.splitProps(props, ["component"]);
671
- const comp = p.component,
671
+ function createDynamic(component, props) {
672
+ const comp = component(),
672
673
  t = typeof comp;
673
674
  if (comp) {
674
- if (t === "function") return comp(others);else if (t === "string") {
675
- return ssrElement(comp, others, undefined, true);
675
+ if (t === "function") return comp(props);else if (t === "string") {
676
+ return ssrElement(comp, props, undefined, true);
676
677
  }
677
678
  }
678
679
  }
680
+ function Dynamic(props) {
681
+ const [, others] = solidJs.splitProps(props, ["component"]);
682
+ return createDynamic(() => props.component, others);
683
+ }
679
684
  function Portal(props) {
680
685
  return "";
681
686
  }
@@ -754,6 +759,7 @@ exports.addEventListener = notSup;
754
759
  exports.assign = notSup;
755
760
  exports.classList = notSup;
756
761
  exports.className = notSup;
762
+ exports.createDynamic = createDynamic;
757
763
  exports.delegateEvents = notSup;
758
764
  exports.dynamicProperty = notSup;
759
765
  exports.escape = escape;
@@ -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;
@@ -858,7 +858,10 @@ function ssrElement(tag, props, children, needsId) {
858
858
  const prop = keys[i];
859
859
  if (ChildProperties.has(prop)) {
860
860
  if (children === undefined && !skipChildren)
861
- children = prop === "innerHTML" ? props[prop] : escape(props[prop]);
861
+ children =
862
+ tag === "script" || tag === "style" || prop === "innerHTML"
863
+ ? props[prop]
864
+ : escape(props[prop]);
862
865
  continue;
863
866
  }
864
867
  const value = props[prop];
@@ -977,7 +980,7 @@ function getHydrationKey() {
977
980
  return hydrate && !hydrate.noHydrate && sharedConfig.getNextContextId();
978
981
  }
979
982
  function useAssets(fn) {
980
- sharedConfig.context.assets.push(() => resolveSSRNode(fn()));
983
+ sharedConfig.context.assets.push(() => resolveSSRNode(escape(fn())));
981
984
  }
982
985
  function getAssets() {
983
986
  const assets = sharedConfig.context.assets;
@@ -1023,7 +1026,9 @@ function injectAssets(assets, html) {
1023
1026
  if (!assets || !assets.length) return html;
1024
1027
  let out = "";
1025
1028
  for (let i = 0, len = assets.length; i < len; i++) out += assets[i]();
1026
- return html.replace(`</head>`, out + `</head>`);
1029
+ const index = html.indexOf("</head>");
1030
+ if (index === -1) return html;
1031
+ return html.slice(0, index) + out + html.slice(index);
1027
1032
  }
1028
1033
  function injectScripts(html, scripts, nonce) {
1029
1034
  const tag = `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>`;
@@ -1140,17 +1145,20 @@ function notSup() {
1140
1145
 
1141
1146
  const isServer = true;
1142
1147
  const isDev = false;
1143
- function Dynamic(props) {
1144
- const [p, others] = splitProps(props, ["component"]);
1145
- const comp = p.component,
1148
+ function createDynamic(component, props) {
1149
+ const comp = component(),
1146
1150
  t = typeof comp;
1147
1151
  if (comp) {
1148
- if (t === "function") return comp(others);
1152
+ if (t === "function") return comp(props);
1149
1153
  else if (t === "string") {
1150
- return ssrElement(comp, others, undefined, true);
1154
+ return ssrElement(comp, props, undefined, true);
1151
1155
  }
1152
1156
  }
1153
1157
  }
1158
+ function Dynamic(props) {
1159
+ const [, others] = splitProps(props, ["component"]);
1160
+ return createDynamic(() => props.component, others);
1161
+ }
1154
1162
  function Portal(props) {
1155
1163
  return "";
1156
1164
  }
@@ -1174,6 +1182,7 @@ export {
1174
1182
  notSup as assign,
1175
1183
  notSup as classList,
1176
1184
  notSup as className,
1185
+ createDynamic,
1177
1186
  notSup as delegateEvents,
1178
1187
  notSup as dynamicProperty,
1179
1188
  escape,
package/web/dist/web.cjs CHANGED
@@ -119,12 +119,12 @@ function render(code, element, init, options = {}) {
119
119
  element.textContent = "";
120
120
  };
121
121
  }
122
- function template(html, isImportNode, isSVG) {
122
+ function template(html, isImportNode, isSVG, isMathML) {
123
123
  let node;
124
124
  const create = () => {
125
- const t = document.createElement("template");
125
+ const t = isMathML ? document.createElementNS("http://www.w3.org/1998/Math/MathML", "template") : document.createElement("template");
126
126
  t.innerHTML = html;
127
- return isSVG ? t.content.firstChild.firstChild : t.content.firstChild;
127
+ return isSVG ? t.content.firstChild.firstChild : isMathML ? t.firstChild : t.content.firstChild;
128
128
  };
129
129
  const fn = isImportNode ? () => solidJs.untrack(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true);
130
130
  fn.cloneNode = fn;
@@ -377,7 +377,7 @@ function assignProp(node, prop, value, prev, isSVG, skipRef, props) {
377
377
  setAttribute(node, prop.slice(5), value);
378
378
  } else if (prop.slice(0, 5) === "bool:") {
379
379
  setBoolAttribute(node, prop.slice(5), value);
380
- } else if ((forceProp = prop.slice(0, 5) === "prop:") || (isChildProp = ChildProperties.has(prop)) || !isSVG && ((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-") || 'is' in props)) {
380
+ } else if ((forceProp = prop.slice(0, 5) === "prop:") || (isChildProp = ChildProperties.has(prop)) || !isSVG && ((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-") || "is" in props)) {
381
381
  if (forceProp) {
382
382
  prop = prop.slice(5);
383
383
  isProp = true;
@@ -661,22 +661,25 @@ function Portal(props) {
661
661
  });
662
662
  return marker;
663
663
  }
664
- function Dynamic(props) {
665
- const [p, others] = solidJs.splitProps(props, ["component"]);
666
- const cached = solidJs.createMemo(() => p.component);
664
+ function createDynamic(component, props) {
665
+ const cached = solidJs.createMemo(component);
667
666
  return solidJs.createMemo(() => {
668
667
  const component = cached();
669
668
  switch (typeof component) {
670
669
  case "function":
671
- return solidJs.untrack(() => component(others));
670
+ return solidJs.untrack(() => component(props));
672
671
  case "string":
673
672
  const isSvg = SVGElements.has(component);
674
673
  const el = solidJs.sharedConfig.context ? getNextElement() : createElement(component, isSvg);
675
- spread(el, others, isSvg);
674
+ spread(el, props, isSvg);
676
675
  return el;
677
676
  }
678
677
  });
679
678
  }
679
+ function Dynamic(props) {
680
+ const [, others] = solidJs.splitProps(props, ["component"]);
681
+ return createDynamic(() => props.component, others);
682
+ }
680
683
 
681
684
  Object.defineProperty(exports, "ErrorBoundary", {
682
685
  enumerable: true,
@@ -753,6 +756,7 @@ exports.assign = assign;
753
756
  exports.classList = classList;
754
757
  exports.className = className;
755
758
  exports.clearDelegatedEvents = clearDelegatedEvents;
759
+ exports.createDynamic = createDynamic;
756
760
  exports.delegateEvents = delegateEvents;
757
761
  exports.dynamicProperty = dynamicProperty;
758
762
  exports.escape = escape;
package/web/dist/web.js CHANGED
@@ -565,12 +565,14 @@ function render(code, element, init, options = {}) {
565
565
  element.textContent = "";
566
566
  };
567
567
  }
568
- function template(html, isImportNode, isSVG) {
568
+ function template(html, isImportNode, isSVG, isMathML) {
569
569
  let node;
570
570
  const create = () => {
571
- const t = document.createElement("template");
571
+ const t = isMathML
572
+ ? document.createElementNS("http://www.w3.org/1998/Math/MathML", "template")
573
+ : document.createElement("template");
572
574
  t.innerHTML = html;
573
- return isSVG ? t.content.firstChild.firstChild : t.content.firstChild;
575
+ return isSVG ? t.content.firstChild.firstChild : isMathML ? t.firstChild : t.content.firstChild;
574
576
  };
575
577
  const fn = isImportNode
576
578
  ? () => untrack(() => document.importNode(node || (node = create()), true))
@@ -1142,22 +1144,25 @@ function Portal(props) {
1142
1144
  );
1143
1145
  return marker;
1144
1146
  }
1145
- function Dynamic(props) {
1146
- const [p, others] = splitProps(props, ["component"]);
1147
- const cached = createMemo(() => p.component);
1147
+ function createDynamic(component, props) {
1148
+ const cached = createMemo(component);
1148
1149
  return createMemo(() => {
1149
1150
  const component = cached();
1150
1151
  switch (typeof component) {
1151
1152
  case "function":
1152
- return untrack(() => component(others));
1153
+ return untrack(() => component(props));
1153
1154
  case "string":
1154
1155
  const isSvg = SVGElements.has(component);
1155
1156
  const el = sharedConfig.context ? getNextElement() : createElement(component, isSvg);
1156
- spread(el, others, isSvg);
1157
+ spread(el, props, isSvg);
1157
1158
  return el;
1158
1159
  }
1159
1160
  });
1160
1161
  }
1162
+ function Dynamic(props) {
1163
+ const [, others] = splitProps(props, ["component"]);
1164
+ return createDynamic(() => props.component, others);
1165
+ }
1161
1166
 
1162
1167
  export {
1163
1168
  Aliases,
@@ -1179,6 +1184,7 @@ export {
1179
1184
  classList,
1180
1185
  className,
1181
1186
  clearDelegatedEvents,
1187
+ createDynamic,
1182
1188
  delegateEvents,
1183
1189
  dynamicProperty,
1184
1190
  escape,
@@ -44,6 +44,22 @@ export type DynamicProps<T extends ValidComponent, P = ComponentProps<T>> = {
44
44
  } & {
45
45
  component: T | undefined;
46
46
  };
47
+ /**
48
+ * Renders an arbitrary component or element with the given props
49
+ *
50
+ * This is a lower level version of the `Dynamic` component, useful for
51
+ * performance optimizations in libraries. Do not use this unless you know
52
+ * what you are doing.
53
+ * ```typescript
54
+ * const element = () => multiline() ? 'textarea' : 'input';
55
+ * createDynamic(element, { value: value() });
56
+ * ```
57
+ * @description https://docs.solidjs.com/reference/components/dynamic
58
+ */
59
+ export declare function createDynamic<T extends ValidComponent>(
60
+ component: () => T | undefined,
61
+ props: ComponentProps<T>
62
+ ): JSX.Element;
47
63
  /**
48
64
  * Renders an arbitrary custom or native component and passes the other props
49
65
  * ```typescript
@@ -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;