@server/next 0.28.1 → 0.28.2

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@server/next",
3
- "version": "0.28.1",
3
+ "version": "0.28.2",
4
4
  "description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
5
5
  "homepage": "https://server-js.com/",
6
6
  "repository": "https://github.com/franciscop/server-next.git",
@@ -3,6 +3,7 @@ const entities = {
3
3
  "<": "&lt;",
4
4
  ">": "&gt;",
5
5
  '"': "&quot;",
6
+ "'": "&#39;",
6
7
  };
7
8
 
8
9
  const encode = (str = "") => {
@@ -40,34 +41,54 @@ const minifyCss = (str) =>
40
41
  .replace(/(\{) (\w)/g, "$1$2")
41
42
  .trim();
42
43
 
44
+ const REACT_ELEMENT_TYPE = Symbol.for("react.element");
45
+
43
46
  const isReactElement = (val) =>
44
- val !== null && typeof val === "object" && "type" in val && "props" in val;
47
+ val !== null &&
48
+ typeof val === "object" &&
49
+ (val.$$typeof === REACT_ELEMENT_TYPE || // real React
50
+ ("type" in val && "props" in val)); // your test objects
51
+
52
+ const resolve = (val) => {
53
+ while (typeof val === "function") val = val();
54
+ if (isReactElement(val)) {
55
+ val = jsx(val.type, val.props || {});
56
+ }
57
+ return val ?? "";
58
+ };
45
59
 
46
60
  const renderChild = (child) => {
47
- if (!isValidChild(child)) return "";
48
- if (typeof child === "function") return child();
49
- if (typeof child === "number") return String(child);
50
- if (typeof child === "string") return encode(child);
51
- if (Array.isArray(child)) return child.flat().map(renderChild).join("");
61
+ while (typeof child === "function") child = child();
62
+
63
+ if (Array.isArray(child)) {
64
+ return child.map(renderChild).join("");
65
+ }
66
+
52
67
  if (isReactElement(child)) {
53
- const result = jsx(child.type, child.props || {});
54
- return typeof result === "function" ? result() : result ?? "";
68
+ return resolve(jsx(child.type, child.props || {}));
55
69
  }
70
+
71
+ if (typeof child === "string") return encode(child);
72
+ if (typeof child === "number") return String(child);
73
+
74
+ if (!isValidChild(child)) return "";
75
+
76
+ console.warn("Unknown child:", child);
56
77
  return "";
57
78
  };
58
79
 
59
80
  const jsx = (tag, { children, ...props }) => {
60
81
  if (typeof tag === "function") {
61
- const result = tag({ children, ...props });
62
- if (isReactElement(result)) return jsx(result.type, result.props || {});
63
- return result ?? (() => "");
82
+ return () => renderChild(tag({ children, ...props }));
64
83
  }
65
84
 
66
85
  // Handle React forwardRef objects: { render: fn }
67
- if (typeof tag === "object" && tag !== null && typeof tag.render === "function") {
68
- const result = tag.render({ children, ...props }, null);
69
- if (isReactElement(result)) return jsx(result.type, result.props || {});
70
- return result ?? (() => "");
86
+ if (
87
+ typeof tag === "object" &&
88
+ tag !== null &&
89
+ typeof tag.render === "function"
90
+ ) {
91
+ return () => renderChild(tag.render({ children, ...props }, null));
71
92
  }
72
93
 
73
94
  if (tag === "script" && children) {
@@ -88,6 +109,7 @@ const jsx = (tag, { children, ...props }) => {
88
109
 
89
110
  children = (Array.isArray(children) ? children.flat() : [children])
90
111
  .map(renderChild)
112
+ .map((c) => (typeof c === "string" ? c : ""))
91
113
  .join("");
92
114
 
93
115
  if (!tag) return () => children;