hono 4.5.5 → 4.5.7

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.
@@ -41,13 +41,14 @@ const escapeRe = /[&<>'"]/;
41
41
  const stringBufferToString = async (buffer, callbacks) => {
42
42
  let str = "";
43
43
  callbacks ||= [];
44
- for (let i = buffer.length - 1; ; i--) {
45
- str += buffer[i];
44
+ const resolvedBuffer = await Promise.all(buffer);
45
+ for (let i = resolvedBuffer.length - 1; ; i--) {
46
+ str += resolvedBuffer[i];
46
47
  i--;
47
48
  if (i < 0) {
48
49
  break;
49
50
  }
50
- let r = await buffer[i];
51
+ let r = resolvedBuffer[i];
51
52
  if (typeof r === "object") {
52
53
  callbacks.push(...r.callbacks || []);
53
54
  }
@@ -25,8 +25,8 @@ var import_cookie = require("../helper/cookie");
25
25
  var import_http_exception = require("../http-exception");
26
26
  var import_buffer = require("../utils/buffer");
27
27
  const jsonRegex = /^application\/([a-z-\.]+\+)?json(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/;
28
- const multipartRegex = /^multipart\/form-data(; boundary=[a-zA-Z0-9'"()+_,\-./:=?]+)?$/;
29
- const urlencodedRegex = /^application\/x-www-form-urlencoded$/;
28
+ const multipartRegex = /^multipart\/form-data(;\s?boundary=[a-zA-Z0-9'"()+_,\-./:=?]+)?$/;
29
+ const urlencodedRegex = /^application\/x-www-form-urlencoded(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/;
30
30
  const validator = (target, validationFunc) => {
31
31
  return async (c, next) => {
32
32
  let value = {};
@@ -64,12 +64,13 @@ const validator = (target, validationFunc) => {
64
64
  const form = {};
65
65
  formData.forEach((value2, key) => {
66
66
  if (key.endsWith("[]")) {
67
- if (form[key] === void 0) {
68
- form[key] = [value2];
69
- } else if (Array.isArray(form[key])) {
70
- ;
71
- form[key].push(value2);
72
- }
67
+ ;
68
+ (form[key] ??= []).push(value2);
69
+ } else if (Array.isArray(form[key])) {
70
+ ;
71
+ form[key].push(value2);
72
+ } else if (key in form) {
73
+ form[key] = [form[key], value2];
73
74
  } else {
74
75
  form[key] = value2;
75
76
  }
@@ -7,8 +7,8 @@ var mergePath = (base, path) => {
7
7
  };
8
8
  var replaceUrlParam = (urlString, params) => {
9
9
  for (const [k, v] of Object.entries(params)) {
10
- const reg = new RegExp("/:" + k + "(?:{[^/]+})?");
11
- urlString = urlString.replace(reg, `/${v}`);
10
+ const reg = new RegExp("/:" + k + "(?:{[^/]+})?\\??");
11
+ urlString = urlString.replace(reg, v ? `/${v}` : "");
12
12
  }
13
13
  return urlString;
14
14
  };
@@ -1,7 +1,7 @@
1
1
  // src/jsx/dom/context.ts
2
2
  import { DOM_ERROR_HANDLER } from "../constants.js";
3
3
  import { globalContexts } from "../context.js";
4
- import { newJSXNode, setInternalTagFlag } from "./utils.js";
4
+ import { setInternalTagFlag } from "./utils.js";
5
5
  var createContextProviderFunction = (values) => ({ value, children }) => {
6
6
  if (!children) {
7
7
  return void 0;
@@ -27,7 +27,7 @@ var createContextProviderFunction = (values) => ({ value, children }) => {
27
27
  }),
28
28
  props: {}
29
29
  });
30
- const res = newJSXNode({ tag: "", props });
30
+ const res = { tag: "", props, type: "" };
31
31
  res[DOM_ERROR_HANDLER] = (err) => {
32
32
  values.pop();
33
33
  throw err;
@@ -1,5 +1,4 @@
1
1
  // src/jsx/dom/intrinsic-element/components.ts
2
- import { newJSXNode } from "../utils.js";
3
2
  import { createPortal, getNameSpaceContext } from "../render.js";
4
3
  import { useContext } from "../../context.js";
5
4
  import { use, useCallback, useMemo, useState } from "../../hooks/index.js";
@@ -38,10 +37,12 @@ var blockingPromiseMap = /* @__PURE__ */ Object.create(null);
38
37
  var createdElements = /* @__PURE__ */ Object.create(null);
39
38
  var documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportBlocking) => {
40
39
  if (props?.itemProp) {
41
- return newJSXNode({
40
+ return {
42
41
  tag,
43
- props
44
- });
42
+ props,
43
+ type: tag,
44
+ ref: props.ref
45
+ };
45
46
  }
46
47
  const head = document.head;
47
48
  let { onLoad, onError, precedence, blocking, ...restProps } = props;
@@ -157,13 +158,15 @@ var documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportBlo
157
158
  use(promise);
158
159
  }
159
160
  }
160
- const jsxNode = newJSXNode({
161
+ const jsxNode = {
161
162
  tag,
163
+ type: tag,
162
164
  props: {
163
165
  ...restProps,
164
166
  ref
165
- }
166
- });
167
+ },
168
+ ref
169
+ };
167
170
  jsxNode.p = preserveNodeType;
168
171
  if (element) {
169
172
  jsxNode.e = element;
@@ -177,28 +180,34 @@ var title = (props) => {
177
180
  const nameSpaceContext = getNameSpaceContext();
178
181
  const ns = nameSpaceContext && useContext(nameSpaceContext);
179
182
  if (ns?.endsWith("svg")) {
180
- return newJSXNode({
183
+ return {
181
184
  tag: "title",
182
- props
183
- });
185
+ props,
186
+ type: "title",
187
+ ref: props.ref
188
+ };
184
189
  }
185
190
  return documentMetadataTag("title", props, void 0, false, false);
186
191
  };
187
192
  var script = (props) => {
188
193
  if (!props || ["src", "async"].some((k) => !props[k])) {
189
- return newJSXNode({
190
- tag: "style",
191
- props
192
- });
194
+ return {
195
+ tag: "script",
196
+ props,
197
+ type: "script",
198
+ ref: props.ref
199
+ };
193
200
  }
194
201
  return documentMetadataTag("script", props, 1, false, true);
195
202
  };
196
203
  var style = (props) => {
197
204
  if (!props || !["href", "precedence"].every((k) => k in props)) {
198
- return newJSXNode({
205
+ return {
199
206
  tag: "style",
200
- props
201
- });
207
+ props,
208
+ type: "style",
209
+ ref: props.ref
210
+ };
202
211
  }
203
212
  props["data-href"] = props.href;
204
213
  delete props.href;
@@ -206,10 +215,12 @@ var style = (props) => {
206
215
  };
207
216
  var link = (props) => {
208
217
  if (!props || ["onLoad", "onError"].some((k) => k in props) || props.rel === "stylesheet" && (!("precedence" in props) || "disabled" in props)) {
209
- return newJSXNode({
218
+ return {
210
219
  tag: "link",
211
- props
212
- });
220
+ props,
221
+ type: "link",
222
+ ref: props.ref
223
+ };
213
224
  }
214
225
  return documentMetadataTag("link", props, 1, "precedence" in props, true);
215
226
  };
@@ -250,7 +261,7 @@ var form = (props) => {
250
261
  });
251
262
  const [data, isDirty] = state;
252
263
  state[1] = false;
253
- return newJSXNode({
264
+ return {
254
265
  tag: FormContext,
255
266
  props: {
256
267
  value: {
@@ -259,16 +270,18 @@ var form = (props) => {
259
270
  method: data ? "post" : null,
260
271
  action: data ? action : null
261
272
  },
262
- children: newJSXNode({
273
+ children: {
263
274
  tag: "form",
264
275
  props: {
265
276
  ...restProps,
266
277
  ref
267
- }
268
- })
278
+ },
279
+ type: "form",
280
+ ref
281
+ }
269
282
  },
270
283
  f: isDirty
271
- });
284
+ };
272
285
  };
273
286
  var formActionableElement = (tag, {
274
287
  formAction,
@@ -288,10 +301,12 @@ var formActionableElement = (tag, {
288
301
  };
289
302
  });
290
303
  }
291
- return newJSXNode({
304
+ return {
292
305
  tag,
293
- props
294
- });
306
+ props,
307
+ type: tag,
308
+ ref: props.ref
309
+ };
295
310
  };
296
311
  var input = (props) => formActionableElement("input", props);
297
312
  var button = (props) => formActionableElement("button", props);
@@ -1,12 +1,16 @@
1
1
  // src/jsx/dom/jsx-dev-runtime.ts
2
- import { newJSXNode } from "./utils.js";
3
2
  import * as intrinsicElementTags from "./intrinsic-element/components.js";
4
3
  var jsxDEV = (tag, props, key) => {
5
- return newJSXNode({
6
- tag: typeof tag === "string" && intrinsicElementTags[tag] || tag,
4
+ if (typeof tag === "string" && intrinsicElementTags[tag]) {
5
+ tag = intrinsicElementTags[tag];
6
+ }
7
+ return {
8
+ tag,
9
+ type: tag,
7
10
  props,
8
- key
9
- });
11
+ key,
12
+ ref: props.ref
13
+ };
10
14
  };
11
15
  var Fragment = (props) => jsxDEV("", props, void 0);
12
16
  export {
@@ -5,7 +5,6 @@ import { globalContexts as globalJSXContexts, useContext } from "../context.js";
5
5
  import { STASH_EFFECT } from "../hooks/index.js";
6
6
  import { normalizeIntrinsicElementKey, styleObjectForEach } from "../utils.js";
7
7
  import { createContext } from "./context.js";
8
- import { newJSXNode } from "./utils.js";
9
8
  var HONO_PORTAL_ELEMENT = "_hp";
10
9
  var eventAliasMap = {
11
10
  Change: "Input",
@@ -15,36 +14,47 @@ var nameSpaceMap = {
15
14
  svg: "2000/svg",
16
15
  math: "1998/Math/MathML"
17
16
  };
18
- var skipProps = /* @__PURE__ */ new Set(["children"]);
19
17
  var buildDataStack = [];
20
18
  var refCleanupMap = /* @__PURE__ */ new WeakMap();
21
19
  var nameSpaceContext = void 0;
22
20
  var getNameSpaceContext = () => nameSpaceContext;
23
21
  var isNodeString = (node) => "t" in node;
22
+ var eventCache = {
23
+ onClick: ["click", false]
24
+ };
24
25
  var getEventSpec = (key) => {
26
+ if (!key.startsWith("on")) {
27
+ return void 0;
28
+ }
29
+ if (eventCache[key]) {
30
+ return eventCache[key];
31
+ }
25
32
  const match = key.match(/^on([A-Z][a-zA-Z]+?(?:PointerCapture)?)(Capture)?$/);
26
33
  if (match) {
27
34
  const [, eventName, capture] = match;
28
- return [(eventAliasMap[eventName] || eventName).toLowerCase(), !!capture];
35
+ return eventCache[key] = [(eventAliasMap[eventName] || eventName).toLowerCase(), !!capture];
29
36
  }
30
37
  return void 0;
31
38
  };
32
- var toAttributeName = (element, key) => element instanceof SVGElement && /[A-Z]/.test(key) && (key in element.style || key.match(/^(?:o|pai|str|u|ve)/)) ? key.replace(/([A-Z])/g, "-$1").toLowerCase() : key;
39
+ var toAttributeName = (element, key) => nameSpaceContext && element instanceof SVGElement && /[A-Z]/.test(key) && (key in element.style || key.match(/^(?:o|pai|str|u|ve)/)) ? key.replace(/([A-Z])/g, "-$1").toLowerCase() : key;
33
40
  var applyProps = (container, attributes, oldAttributes) => {
34
41
  attributes ||= {};
35
- for (let [key, value] of Object.entries(attributes)) {
36
- if (!skipProps.has(key) && (!oldAttributes || oldAttributes[key] !== value)) {
42
+ for (let key in attributes) {
43
+ const value = attributes[key];
44
+ if (key !== "children" && (!oldAttributes || oldAttributes[key] !== value)) {
37
45
  key = normalizeIntrinsicElementKey(key);
38
46
  const eventSpec = getEventSpec(key);
39
47
  if (eventSpec) {
40
- if (oldAttributes) {
41
- container.removeEventListener(eventSpec[0], oldAttributes[key], eventSpec[1]);
42
- }
43
- if (value != null) {
44
- if (typeof value !== "function") {
45
- throw new Error(`Event handler for "${key}" is not a function`);
48
+ if (oldAttributes?.[key] !== value) {
49
+ if (oldAttributes) {
50
+ container.removeEventListener(eventSpec[0], oldAttributes[key], eventSpec[1]);
51
+ }
52
+ if (value != null) {
53
+ if (typeof value !== "function") {
54
+ throw new Error(`Event handler for "${key}" is not a function`);
55
+ }
56
+ container.addEventListener(eventSpec[0], value, eventSpec[1]);
46
57
  }
47
- container.addEventListener(eventSpec[0], value, eventSpec[1]);
48
58
  }
49
59
  } else if (key === "dangerouslySetInnerHTML" && value) {
50
60
  container.innerHTML = value.__html;
@@ -68,8 +78,8 @@ var applyProps = (container, attributes, oldAttributes) => {
68
78
  }
69
79
  }
70
80
  } else {
71
- const nodeName = container.nodeName;
72
81
  if (key === "value") {
82
+ const nodeName = container.nodeName;
73
83
  if (nodeName === "INPUT" || nodeName === "TEXTAREA" || nodeName === "SELECT") {
74
84
  ;
75
85
  container.value = value === null || value === void 0 || value === false ? null : value;
@@ -84,7 +94,7 @@ var applyProps = (container, attributes, oldAttributes) => {
84
94
  continue;
85
95
  }
86
96
  }
87
- } else if (key === "checked" && nodeName === "INPUT" || key === "selected" && nodeName === "OPTION") {
97
+ } else if (key === "checked" && container.nodeName === "INPUT" || key === "selected" && container.nodeName === "OPTION") {
88
98
  ;
89
99
  container[key] = value;
90
100
  }
@@ -102,8 +112,9 @@ var applyProps = (container, attributes, oldAttributes) => {
102
112
  }
103
113
  }
104
114
  if (oldAttributes) {
105
- for (let [key, value] of Object.entries(oldAttributes)) {
106
- if (!skipProps.has(key) && !(key in attributes)) {
115
+ for (let key in oldAttributes) {
116
+ const value = oldAttributes[key];
117
+ if (key !== "children" && !(key in attributes)) {
107
118
  key = normalizeIntrinsicElementKey(key);
108
119
  const eventSpec = getEventSpec(key);
109
120
  if (eventSpec) {
@@ -118,27 +129,24 @@ var applyProps = (container, attributes, oldAttributes) => {
118
129
  }
119
130
  };
120
131
  var invokeTag = (context, node) => {
121
- if (node.s) {
122
- const res = node.s;
123
- node.s = void 0;
124
- return res;
125
- }
126
132
  node[DOM_STASH][0] = 0;
127
133
  buildDataStack.push([context, node]);
128
134
  const func = node.tag[DOM_RENDERER] || node.tag;
135
+ const props = func.defaultProps ? {
136
+ ...func.defaultProps,
137
+ ...node.props
138
+ } : node.props;
129
139
  try {
130
- return [
131
- func.call(null, {
132
- ...func.defaultProps || {},
133
- ...node.props
134
- })
135
- ];
140
+ return [func.call(null, props)];
136
141
  } finally {
137
142
  buildDataStack.pop();
138
143
  }
139
144
  };
140
145
  var getNextChildren = (node, container, nextChildren, childrenToRemove, callbacks) => {
141
- childrenToRemove.push(...node.vR);
146
+ if (node.vR?.length) {
147
+ childrenToRemove.push(...node.vR);
148
+ delete node.vR;
149
+ }
142
150
  if (typeof node.tag === "function") {
143
151
  node[DOM_STASH][1][STASH_EFFECT]?.forEach((data) => callbacks.push(data));
144
152
  }
@@ -148,16 +156,33 @@ var getNextChildren = (node, container, nextChildren, childrenToRemove, callback
148
156
  } else {
149
157
  if (typeof child.tag === "function" || child.tag === "") {
150
158
  child.c = container;
159
+ const currentNextChildrenIndex = nextChildren.length;
151
160
  getNextChildren(child, container, nextChildren, childrenToRemove, callbacks);
161
+ if (child.s) {
162
+ for (let i = currentNextChildrenIndex; i < nextChildren.length; i++) {
163
+ nextChildren[i].s = true;
164
+ }
165
+ child.s = false;
166
+ }
152
167
  } else {
153
168
  nextChildren.push(child);
154
- childrenToRemove.push(...child.vR);
169
+ if (child.vR?.length) {
170
+ childrenToRemove.push(...child.vR);
171
+ delete child.vR;
172
+ }
155
173
  }
156
174
  }
157
175
  });
158
176
  };
159
177
  var findInsertBefore = (node) => {
160
- return !node ? null : node.tag === HONO_PORTAL_ELEMENT ? findInsertBefore(node.nN) : node.e || node.vC && node.pP && findInsertBefore(node.vC[0]) || findInsertBefore(node.nN);
178
+ for (; ; node = node.tag === HONO_PORTAL_ELEMENT || !node.vC || !node.pP ? node.nN : node.vC[0]) {
179
+ if (!node) {
180
+ return null;
181
+ }
182
+ if (node.tag !== HONO_PORTAL_ELEMENT && node.e) {
183
+ return node.e;
184
+ }
185
+ }
161
186
  };
162
187
  var removeNode = (node) => {
163
188
  if (!isNodeString(node)) {
@@ -179,16 +204,9 @@ var removeNode = (node) => {
179
204
  node.a = true;
180
205
  }
181
206
  };
182
- var apply = (node, container) => {
207
+ var apply = (node, container, isNew) => {
183
208
  node.c = container;
184
- applyNodeObject(node, container);
185
- };
186
- var applyNode = (node, container) => {
187
- if (isNodeString(node)) {
188
- container.textContent = node.t;
189
- } else {
190
- applyNodeObject(node, container);
191
- }
209
+ applyNodeObject(node, container, isNew);
192
210
  };
193
211
  var findChildNodeIndex = (childNodes, child) => {
194
212
  if (!child) {
@@ -202,39 +220,81 @@ var findChildNodeIndex = (childNodes, child) => {
202
220
  return;
203
221
  };
204
222
  var cancelBuild = Symbol();
205
- var applyNodeObject = (node, container) => {
223
+ var applyNodeObject = (node, container, isNew) => {
206
224
  const next = [];
207
225
  const remove = [];
208
226
  const callbacks = [];
209
227
  getNextChildren(node, container, next, remove, callbacks);
210
- const childNodes = container.childNodes;
211
- let offset = findChildNodeIndex(childNodes, findInsertBefore(node.nN)) ?? findChildNodeIndex(childNodes, next.find((n) => n.tag !== HONO_PORTAL_ELEMENT && n.e)?.e) ?? childNodes.length;
228
+ remove.forEach(removeNode);
229
+ const childNodes = isNew ? void 0 : container.childNodes;
230
+ let offset;
231
+ if (isNew) {
232
+ offset = -1;
233
+ } else {
234
+ offset = (childNodes.length && (findChildNodeIndex(childNodes, findInsertBefore(node.nN)) ?? findChildNodeIndex(
235
+ childNodes,
236
+ next.find((n) => n.tag !== HONO_PORTAL_ELEMENT && n.e)?.e
237
+ ))) ?? -1;
238
+ if (offset === -1) {
239
+ isNew = true;
240
+ }
241
+ }
212
242
  for (let i = 0, len = next.length; i < len; i++, offset++) {
213
243
  const child = next[i];
214
244
  let el;
215
- if (isNodeString(child)) {
216
- if (child.e && child.d) {
217
- child.e.textContent = child.t;
218
- }
219
- child.d = false;
220
- el = child.e ||= document.createTextNode(child.t);
245
+ if (child.s && child.e) {
246
+ el = child.e;
247
+ child.s = false;
221
248
  } else {
222
- el = child.e ||= child.n ? document.createElementNS(child.n, child.tag) : document.createElement(child.tag);
223
- applyProps(el, child.props, child.pP);
224
- applyNode(child, el);
249
+ const isNewLocal = isNew || !child.e;
250
+ if (isNodeString(child)) {
251
+ if (child.e && child.d) {
252
+ child.e.textContent = child.t;
253
+ }
254
+ child.d = false;
255
+ el = child.e ||= document.createTextNode(child.t);
256
+ } else {
257
+ el = child.e ||= child.n ? document.createElementNS(child.n, child.tag) : document.createElement(child.tag);
258
+ applyProps(el, child.props, child.pP);
259
+ applyNodeObject(child, el, isNewLocal);
260
+ }
225
261
  }
226
262
  if (child.tag === HONO_PORTAL_ELEMENT) {
227
263
  offset--;
228
- } else if (childNodes[offset] !== el && childNodes[offset - 1] !== child.e) {
229
- container.insertBefore(el, childNodes[offset] || null);
264
+ } else if (isNew) {
265
+ if (!el.parentNode) {
266
+ container.appendChild(el);
267
+ }
268
+ } else if (childNodes[offset] !== el && childNodes[offset - 1] !== el) {
269
+ if (childNodes[offset + 1] === el) {
270
+ container.appendChild(childNodes[offset]);
271
+ } else {
272
+ container.insertBefore(el, childNodes[offset] || null);
273
+ }
274
+ }
275
+ }
276
+ if (node.pP) {
277
+ delete node.pP;
278
+ }
279
+ if (callbacks.length) {
280
+ const useLayoutEffectCbs = [];
281
+ const useEffectCbs = [];
282
+ callbacks.forEach(([, useLayoutEffectCb, , useEffectCb, useInsertionEffectCb]) => {
283
+ if (useLayoutEffectCb) {
284
+ useLayoutEffectCbs.push(useLayoutEffectCb);
285
+ }
286
+ if (useEffectCb) {
287
+ useEffectCbs.push(useEffectCb);
288
+ }
289
+ useInsertionEffectCb?.();
290
+ });
291
+ useLayoutEffectCbs.forEach((cb) => cb());
292
+ if (useEffectCbs.length) {
293
+ requestAnimationFrame(() => {
294
+ useEffectCbs.forEach((cb) => cb());
295
+ });
230
296
  }
231
297
  }
232
- remove.forEach(removeNode);
233
- callbacks.forEach(([, , , , cb]) => cb?.());
234
- callbacks.forEach(([, cb]) => cb?.());
235
- requestAnimationFrame(() => {
236
- callbacks.forEach(([, , , cb]) => cb?.());
237
- });
238
298
  };
239
299
  var fallbackUpdateFnArrayMap = /* @__PURE__ */ new WeakMap();
240
300
  var build = (context, node, children) => {
@@ -249,30 +309,33 @@ var build = (context, node, children) => {
249
309
  foundErrorHandler = children[0][DOM_ERROR_HANDLER];
250
310
  context[5].push([context, foundErrorHandler, node]);
251
311
  }
252
- const oldVChildren = buildWithPreviousChildren ? [...node.pC] : node.vC ? [...node.vC] : [];
312
+ const oldVChildren = buildWithPreviousChildren ? [...node.pC] : node.vC ? [...node.vC] : void 0;
253
313
  const vChildren = [];
254
- node.vR = buildWithPreviousChildren ? [...node.vC] : [];
255
314
  let prevNode;
256
- children.flat().forEach((c) => {
257
- let child = buildNode(c);
315
+ for (let i = 0; i < children.length; i++) {
316
+ if (Array.isArray(children[i])) {
317
+ children.splice(i, 1, ...children[i].flat());
318
+ }
319
+ let child = buildNode(children[i]);
258
320
  if (child) {
259
321
  if (typeof child.tag === "function" && !child.tag[DOM_INTERNAL_TAG]) {
260
322
  if (globalJSXContexts.length > 0) {
261
- child[DOM_STASH][2] = globalJSXContexts.map((c2) => [c2, c2.values.at(-1)]);
323
+ child[DOM_STASH][2] = globalJSXContexts.map((c) => [c, c.values.at(-1)]);
262
324
  }
263
325
  if (context[5]?.length) {
264
326
  child[DOM_STASH][3] = context[5].at(-1);
265
327
  }
266
328
  }
267
329
  let oldChild;
268
- const i = oldVChildren.findIndex(
269
- isNodeString(child) ? (c2) => isNodeString(c2) : child.key !== void 0 ? (c2) => c2.key === child.key : (c2) => c2.tag === child.tag
270
- );
271
- if (i !== -1) {
272
- oldChild = oldVChildren[i];
273
- oldVChildren.splice(i, 1);
330
+ if (oldVChildren && oldVChildren.length) {
331
+ const i2 = oldVChildren.findIndex(
332
+ isNodeString(child) ? (c) => isNodeString(c) : child.key !== void 0 ? (c) => c.key === child.key && c.tag === child.tag : (c) => c.tag === child.tag
333
+ );
334
+ if (i2 !== -1) {
335
+ oldChild = oldVChildren[i2];
336
+ oldVChildren.splice(i2, 1);
337
+ }
274
338
  }
275
- let skipBuild = false;
276
339
  if (oldChild) {
277
340
  if (isNodeString(child)) {
278
341
  if (oldChild.t !== child.t) {
@@ -281,8 +344,6 @@ var build = (context, node, children) => {
281
344
  oldChild.d = true;
282
345
  }
283
346
  child = oldChild;
284
- } else if (oldChild.tag !== child.tag) {
285
- node.vR.push(oldChild);
286
347
  } else {
287
348
  const pP = oldChild.pP = oldChild.props;
288
349
  oldChild.props = child.props;
@@ -293,7 +354,9 @@ var build = (context, node, children) => {
293
354
  if (!oldChild.f) {
294
355
  const prevPropsKeys = Object.keys(pP);
295
356
  const currentProps = oldChild.props;
296
- skipBuild = prevPropsKeys.length === Object.keys(currentProps).length && prevPropsKeys.every((k) => k in currentProps && currentProps[k] === pP[k]);
357
+ if (prevPropsKeys.length === Object.keys(currentProps).length && prevPropsKeys.every((k) => k in currentProps && currentProps[k] === pP[k])) {
358
+ oldChild.s = true;
359
+ }
297
360
  }
298
361
  }
299
362
  child = oldChild;
@@ -304,19 +367,21 @@ var build = (context, node, children) => {
304
367
  child.n = ns;
305
368
  }
306
369
  }
307
- if (!isNodeString(child) && !skipBuild) {
370
+ if (!isNodeString(child) && !child.s) {
308
371
  build(context, child);
309
372
  delete child.f;
310
373
  }
311
374
  vChildren.push(child);
312
- for (let p = prevNode; p && !isNodeString(p); p = p.vC?.at(-1)) {
313
- p.nN = child;
375
+ if (prevNode && !prevNode.s && !child.s) {
376
+ for (let p = prevNode; p && !isNodeString(p); p = p.vC?.at(-1)) {
377
+ p.nN = child;
378
+ }
314
379
  }
315
380
  prevNode = child;
316
381
  }
317
- });
382
+ }
383
+ node.vR = buildWithPreviousChildren ? [...node.vC, ...oldVChildren || []] : oldVChildren || [];
318
384
  node.vC = vChildren;
319
- node.vR.push(...oldVChildren);
320
385
  if (buildWithPreviousChildren) {
321
386
  delete node.pC;
322
387
  }
@@ -351,7 +416,7 @@ var build = (context, node, children) => {
351
416
  } else {
352
417
  build(context, errorHandlerNode, [fallback]);
353
418
  if ((errorHandler.length === 1 || context !== errorHandlerContext) && errorHandlerNode.c) {
354
- apply(errorHandlerNode, errorHandlerNode.c);
419
+ apply(errorHandlerNode, errorHandlerNode.c, false);
355
420
  return;
356
421
  }
357
422
  }
@@ -372,12 +437,14 @@ var buildNode = (node) => {
372
437
  return { t: node.toString(), d: true };
373
438
  } else {
374
439
  if ("vR" in node) {
375
- node = newJSXNode({
440
+ node = {
376
441
  tag: node.tag,
377
442
  props: node.props,
378
443
  key: node.key,
379
- f: node.f
380
- });
444
+ f: node.f,
445
+ type: node.tag,
446
+ ref: node.props.ref
447
+ };
381
448
  }
382
449
  if (typeof node.tag === "function") {
383
450
  ;
@@ -423,7 +490,7 @@ var updateSync = (context, node) => {
423
490
  c.values.pop();
424
491
  });
425
492
  if (context[0] !== 1 || !context[1]) {
426
- apply(node, node.c);
493
+ apply(node, node.c, false);
427
494
  }
428
495
  };
429
496
  var updateMap = /* @__PURE__ */ new WeakMap();
@@ -469,7 +536,7 @@ var renderNode = (node, container) => {
469
536
  build(context, node, void 0);
470
537
  context[4] = false;
471
538
  const fragment = document.createDocumentFragment();
472
- apply(node, fragment);
539
+ apply(node, fragment, true);
473
540
  replaceContainer(node, fragment, container);
474
541
  container.replaceChildren(fragment);
475
542
  };