@solidjs/web 2.0.0-rc.17 → 2.0.0-rc.19

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.
@@ -2,7 +2,7 @@ import { createRenderEffect, createMemo, OBSERVE, getOwner, createRoot, $PROXY,
2
2
  export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, dynamicComponent, getOwner, merge as mergeProps, untrack } from 'solid-js';
3
3
  import { sharedConfig, ssrSanitizeError, beginEdgesRender, reportServerError, viewOf, sourceOwners, ssrHandleError, inServerComponentScope, creationStamp, dynamicCore, getProjectionTrace, shareAsyncIterable } from 'solid-js/internal';
4
4
  export { ssrScope as scope } from 'solid-js/internal';
5
- import { createStream, Serializer, getCrossReferenceHeader, Feature } from 'seroval';
5
+ import { createStream, Feature, getCrossReferenceHeader, crossSerializeStream } from 'seroval';
6
6
  import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
7
7
 
8
8
  const DOMWithState = {
@@ -531,15 +531,92 @@ function resolveSerializerPlugins(customPlugins) {
531
531
  }
532
532
 
533
533
  const defaultDisabledFeatures = () => Feature.AggregateError | Feature.BigIntTypedArray;
534
- const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : Feature.ErrorPrototypeStack;
534
+ const serializeOnlyDisabledFeatures = serializeErrorStacks => (process.env.NODE_ENV === "development" ) ? 0 : Feature.ErrorPrototypeStack;
535
535
  const HYDRATION_GLOBAL = "_$HY.r";
536
- function createSerializer(options) {
537
- return new Serializer({
538
- ...options,
539
- plugins: resolveSerializerPlugins(options.plugins),
540
- disabledFeatures: (options.disabledFeatures === undefined ? defaultDisabledFeatures() : options.disabledFeatures) | serializeOnlyDisabledFeatures(options.serializeErrorStacks)
541
- });
536
+ function createKeyedSerializer(serialize, onError, onDone) {
537
+ const cancels = new Set();
538
+ let pendingWrites = 0;
539
+ let flushed = false;
540
+ let done = false;
541
+ let closed = false;
542
+ const maybeDone = () => {
543
+ if (flushed && pendingWrites === 0 && !done) {
544
+ done = true;
545
+ onDone && onDone();
546
+ }
547
+ };
548
+ return {
549
+ write(key, value) {
550
+ if (flushed) return;
551
+ pendingWrites++;
552
+ let settled = false;
553
+ let failed = false;
554
+ let started = false;
555
+ let cancel = null;
556
+ const settle = () => {
557
+ if (settled) return;
558
+ settled = true;
559
+ if (cancel) cancels.delete(cancel);
560
+ pendingWrites--;
561
+ maybeDone();
562
+ };
563
+ let stream;
564
+ try {
565
+ stream = serialize(key, value, {
566
+ onError: onError && (err => {
567
+ failed = true;
568
+ onError(err);
569
+ if (cancel) {
570
+ cancel();
571
+ settle();
572
+ }
573
+ }),
574
+ onDone: settle
575
+ }, initial => {
576
+ if (initial) started = true;
577
+ return !closed;
578
+ });
579
+ } catch (err) {
580
+ settle();
581
+ throw err;
582
+ }
583
+ if (settled) return;
584
+ if (closed || failed) {
585
+ stream();
586
+ settle();
587
+ return;
588
+ }
589
+ cancel = stream;
590
+ cancels.add(cancel);
591
+ },
592
+ flush() {
593
+ flushed = true;
594
+ maybeDone();
595
+ },
596
+ close() {
597
+ closed = flushed = true;
598
+ for (const cancel of cancels) cancel();
599
+ cancels.clear();
600
+ if (!done) {
601
+ done = true;
602
+ onDone && onDone();
603
+ }
604
+ }
605
+ };
542
606
  }
607
+ const KEY_ESCAPES = {
608
+ '"': '\\"',
609
+ "\\": "\\\\",
610
+ "\n": "\\n",
611
+ "\r": "\\r",
612
+ "\b": "\\b",
613
+ "\t": "\\t",
614
+ "\f": "\\f",
615
+ "<": "\\x3C",
616
+ "\u2028": "\\u2028",
617
+ "\u2029": "\\u2029"
618
+ };
619
+ const serializeKey = key => ("" + key).replace(/["\\\n\r\b\t\f<\u2028\u2029]/g, c => KEY_ESCAPES[c]);
543
620
  function createHydrationSerializer({
544
621
  onData,
545
622
  onDone,
@@ -547,14 +624,20 @@ function createHydrationSerializer({
547
624
  onError,
548
625
  plugins
549
626
  }) {
550
- return createSerializer({
627
+ const resolvedPlugins = resolveSerializerPlugins(plugins);
628
+ const disabledFeatures = defaultDisabledFeatures() | serializeOnlyDisabledFeatures();
629
+ const refs = new Map();
630
+ return createKeyedSerializer((key, value, callbacks, live) => crossSerializeStream(value, {
551
631
  scopeId,
552
- plugins,
553
- globalIdentifier: HYDRATION_GLOBAL,
554
- onData,
555
- onDone,
556
- onError
557
- });
632
+ refs,
633
+ plugins: resolvedPlugins,
634
+ disabledFeatures,
635
+ onSerialize(data, initial) {
636
+ if (!live(initial)) return;
637
+ onData(initial ? HYDRATION_GLOBAL + '["' + serializeKey(key) + '"]=' + data : data);
638
+ },
639
+ ...callbacks
640
+ }), onError, onDone);
558
641
  }
559
642
  function getLocalHeaderScript(id) {
560
643
  return getCrossReferenceHeader(id) + ";";
@@ -1590,7 +1673,7 @@ function isAttrName(prop) {
1590
1673
  if (safeAttrNames.size < 512) safeAttrNames.add(prop);
1591
1674
  return true;
1592
1675
  }
1593
- const REPLACE_SCRIPT = `function $df(e){return _$HY.f?_$HY.f(e):$dfr(e)}function $dfr(e,n,o,t){if(!(n=document.getElementById(e)))return 0;if(!(o=document.getElementById("pl-"+e)))return(_$HY.dq=_$HY.dq||{})[e]=1,0;for(;o&&(8!==o.nodeType||o.nodeValue!=="pl-"+e);)t=o.nextSibling,o.remove(),o=t;t=o.parentNode,o.replaceWith(n.content),n.remove(),(_$HY.v=_$HY.v||{})[e]=1,_$HY.fe(e,t),_$HY.hp&&_$HY.hp[e]&&($dh(_$HY.hp[e]),delete _$HY.hp[e]),$dfd();return 1}function $dfl(e,o,n){if(!(o=document.getElementById("pl-"+e)))return(_$HY.dlq=_$HY.dlq||{})[e]=1,0;if(o._$fl)return 1;for(n=o.nextSibling;n;){if(8===n.nodeType&&n.nodeValue==="pl-"+e){o.parentNode&&o.parentNode.insertBefore(o.content.cloneNode(!0),n),o._$fl=1,$dfd();return 1}n=n.nextSibling}return 0}function $dflj(e,i){for(i=0;i<e.length;i++)$dfl(e[i])}function $dfd(e,i){if(e=_$HY.dq){_$HY.dq=0;for(i in e)$df(i)}if(e=_$HY.dlq){_$HY.dlq=0;for(i in e)$dfl(i)}}function $dfs(e,c,d){(_$HY.sc=_$HY.sc||{})[e]=c,d&&((_$HY.sd=_$HY.sd||{})[e]=1)}function $dfg(e,g,i,k){if(!(g=_$HY.sg&&_$HY.sg[e]))return;for(i=0;i<g.length;i++)if(_$HY.sc&&_$HY.sc[g[i]]>0)return;for(i=0;i<g.length;i++)k=g[i],delete _$HY.sg[k],$df(k)}function $dfc(e){if(--_$HY.sc[e]<=0){delete _$HY.sc[e],_$HY.sg&&_$HY.sg[e]?$dfg(e):!(_$HY.sd&&_$HY.sd[e])&&$df(e);_$HY.sd&&delete _$HY.sd[e]}}function $dfj(e,i,n){for(i=0;i<e.length;i++)if(_$HY.sc&&_$HY.sc[e[i]]>0){for(n=0;n<e.length;n++)(_$HY.sg=_$HY.sg||{})[e[n]]=e;return}for(i=0;i<e.length;i++)$df(e[i])}function $dfe(e,t,k){(t=e.target)&&t.getAttribute&&!t._$dc&&(k=t.getAttribute("data-dfc"))&&(t._$dc=1,$dfc(k))}document.addEventListener("load",$dfe,!0);document.addEventListener("error",$dfe,!0)`;
1676
+ const REPLACE_SCRIPT = `function $df(e){return _$HY.f?_$HY.f(e):$dfr(e)}function $dfr(e,n,o,t){if(!(n=document.getElementById(e)))return 0;if(!(o=document.getElementById("pl-"+e)))return(_$HY.dq=_$HY.dq||{})[e]=1,0;for(;o&&(8!==o.nodeType||o.nodeValue!=="pl-"+e);)t=o.nextSibling,o.remove(),o=t;t=o.parentNode,(_$HY.v=_$HY.v||{})[e]=n.hasAttribute("e")?[...n.content.childNodes]:1,o.replaceWith(n.content),n.remove(),_$HY.fe(e,t),_$HY.hp&&_$HY.hp[e]&&($dh(_$HY.hp[e]),delete _$HY.hp[e]),$dfd();return 1}function $dfl(e,o,n){if(!(o=document.getElementById("pl-"+e)))return(_$HY.dlq=_$HY.dlq||{})[e]=1,0;if(o._$fl)return 1;for(n=o.nextSibling;n;){if(8===n.nodeType&&n.nodeValue==="pl-"+e){o.parentNode&&o.parentNode.insertBefore(o.content.cloneNode(!0),n),o._$fl=1,$dfd();return 1}n=n.nextSibling}return 0}function $dflj(e,i){for(i=0;i<e.length;i++)$dfl(e[i])}function $dfd(e,i){if(e=_$HY.dq){_$HY.dq=0;for(i in e)$df(i)}if(e=_$HY.dlq){_$HY.dlq=0;for(i in e)$dfl(i)}}function $dfs(e,c,d){(_$HY.sc=_$HY.sc||{})[e]=c,d&&((_$HY.sd=_$HY.sd||{})[e]=1)}function $dfg(e,g,i,k){if(!(g=_$HY.sg&&_$HY.sg[e]))return;for(i=0;i<g.length;i++)if(_$HY.sc&&_$HY.sc[g[i]]>0)return;for(i=0;i<g.length;i++)k=g[i],delete _$HY.sg[k],$df(k)}function $dfc(e){if(--_$HY.sc[e]<=0){delete _$HY.sc[e],_$HY.sg&&_$HY.sg[e]?$dfg(e):!(_$HY.sd&&_$HY.sd[e])&&$df(e);_$HY.sd&&delete _$HY.sd[e]}}function $dfj(e,i,n){for(i=0;i<e.length;i++)if(_$HY.sc&&_$HY.sc[e[i]]>0){for(n=0;n<e.length;n++)(_$HY.sg=_$HY.sg||{})[e[n]]=e;return}for(i=0;i<e.length;i++)$df(e[i])}function $dfe(e,t,k){(t=e.target)&&t.getAttribute&&!t._$dc&&(k=t.getAttribute("data-dfc"))&&(t._$dc=1,$dfc(k))}document.addEventListener("load",$dfe,!0);document.addEventListener("error",$dfe,!0)`;
1594
1677
  const HEAD_SCRIPT = `function $dha(o,i,e,n){for(i=0;i<o.length;i++)e=o[i],"t"==e[0]?((n=document.querySelector("title"))?n.hasAttribute("data-dh")||n.setAttribute("data-dhf",n.textContent):(n=document.createElement("title"),document.head.appendChild(n)),n.textContent=e[1],n.setAttribute("data-dh","title")):"r"==e[0]?$dhr(e[1]):(n=document.createElement(e[2]),Object.keys(e[3]).forEach(function(a){n.setAttribute(a,e[3][a])}),null!=e[4]&&(n.textContent=e[4]),n.setAttribute("data-dh",e[1]),document.head.appendChild(n))}function $dhr(v,l,i){for(l=document.head.querySelectorAll("[data-dh]"),i=0;i<l.length;i++)l[i].getAttribute("data-dh")==v&&l[i].remove()}function $dh(o){_$HY.h?_$HY.h(o):$dha(o)}`;
1595
1678
  function renderToString(code, options = {}) {
1596
1679
  const {
@@ -1861,7 +1944,6 @@ function renderToStream(code, options = {}) {
1861
1944
  const blockingPromises = new Set();
1862
1945
  const canBatchStubs = !options.serializer && !options.sink;
1863
1946
  let stubBatch = null;
1864
- const STUB_BATCH_KEY = "$B";
1865
1947
  let stableOrder = false;
1866
1948
  let parkedWrites = null;
1867
1949
  const byKey = (a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
@@ -1876,19 +1958,10 @@ function renderToStream(code, options = {}) {
1876
1958
  };
1877
1959
  const flushStubBatch = () => {
1878
1960
  if (!stubBatch) return;
1879
- const batch = stubBatch;
1961
+ const entries = [...stubBatch];
1880
1962
  stubBatch = null;
1881
- if (batch.size === 1) {
1882
- const [id, p] = batch.entries().next().value;
1883
- serializer.write(id, p);
1884
- return;
1885
- }
1886
- const obj = {};
1887
- const entries = [...batch];
1888
1963
  if (stableOrder) entries.sort(byKey);
1889
- for (const [id, p] of entries) obj[id] = p;
1890
- serializer.write(STUB_BATCH_KEY, obj);
1891
- pushTask(`(b=>{for(var k in b)_$HY.r[k]=b[k];delete _$HY.r["${STUB_BATCH_KEY}"]})(_$HY.r["${STUB_BATCH_KEY}"])`);
1964
+ for (let i = 0; i < entries.length; i++) serializer.write(entries[i][0], entries[i][1]);
1892
1965
  };
1893
1966
  let headerEmitted = false;
1894
1967
  const pushTask = task => {
@@ -1925,6 +1998,7 @@ function renderToStream(code, options = {}) {
1925
1998
  fragment(key, value, meta) {
1926
1999
  const deferActivation = !!meta.revealGroup;
1927
2000
  const styles = meta.styles;
2001
+ const tpl = `<template id="${key}"${meta.error ? " e" : ""}>${value}</template>`;
1928
2002
  for (let i = 0; i < styles.inline.length; i++) {
1929
2003
  buffer.write(renderInlineStyle(styles.inline[i], nonce));
1930
2004
  }
@@ -1932,12 +2006,12 @@ function renderToStream(code, options = {}) {
1932
2006
  const styleAttr = nonceAttr(nonce, "style");
1933
2007
  emitTask(`$dfs("${key}",${styles.links.length},${deferActivation ? 1 : 0})`);
1934
2008
  writeTasks();
1935
- buffer.write(`<template id="${key}">${value}</template>`);
2009
+ buffer.write(tpl);
1936
2010
  for (const entry of styles.links) {
1937
2011
  buffer.write(typeof entry === "string" ? `<link rel="stylesheet" href="${entry}"${styleAttr} data-dfc="${key}">` : `<link${entry.attrHtml}${styleAttr} data-dfc="${key}">`);
1938
2012
  }
1939
2013
  } else {
1940
- buffer.write(`<template id="${key}">${value}</template>`);
2014
+ buffer.write(tpl);
1941
2015
  if (!deferActivation) {
1942
2016
  emitTask(`$df("${key}")`);
1943
2017
  }
@@ -2050,22 +2124,26 @@ function renderToStream(code, options = {}) {
2050
2124
  return raced;
2051
2125
  };
2052
2126
  const abandonSubtree = (key, error) => {
2127
+ if (key == null) return;
2053
2128
  let fragments = 0;
2054
2129
  let serialized = 0;
2055
2130
  for (const [k, entry] of registry) {
2056
- if (k.length > key.length && k.startsWith(key)) {
2131
+ if (k != null && k.length > key.length && k.startsWith(key)) {
2057
2132
  registry.delete(k);
2058
2133
  entry.resolve();
2059
2134
  fragments++;
2060
2135
  }
2061
2136
  }
2137
+ const unregister = [];
2062
2138
  for (const [id, settle] of pendingSerialized) {
2063
2139
  if (id.startsWith(key)) {
2064
2140
  pendingSerialized.delete(id);
2065
2141
  settle();
2066
2142
  serialized++;
2143
+ if (!stubBatch?.delete(id)) unregister.push(`delete _$HY.r[${JSON.stringify(id)}]`);
2067
2144
  }
2068
2145
  }
2146
+ if (unregister.length && !options.sink) pushTask(unregister.join(";"));
2069
2147
  if ((fragments || serialized)) emitFinding({
2070
2148
  code: "SSR_SUBTREE_ABANDONED",
2071
2149
  kind: "ssr",
@@ -2292,7 +2370,7 @@ function renderToStream(code, options = {}) {
2292
2370
  const styles = collectStreamStyles(key, tracking, headStyles);
2293
2371
  const headOps = error ? null : flushHeadFragment(headRegistry, key, nonce);
2294
2372
  if (headOps) emitHeadOps(key, headOps);
2295
- sink.fragment(key, resolveSSRSelectValues(value !== undefined ? value : " "), {
2373
+ sink.fragment(key, resolveSSRSelectValues(value !== undefined ? value : error ? "" : " "), {
2296
2374
  styles,
2297
2375
  revealGroup,
2298
2376
  error: error ? ssrSanitizeError(error, null, undefined, undefined, errorScope) : error
@@ -2852,11 +2930,19 @@ function createLiveHoles(sink, scoped, settled, errorScope) {
2852
2930
  }
2853
2931
  function rowOps(last, rows) {
2854
2932
  const ops = [];
2855
- for (let i = 0; i < rows.length; i++) if (i >= last.length || rows[i] !== last[i]) ops.push([i, rows[i]]);
2856
- return ops.length < rows.length ? {
2933
+ const html = [];
2934
+ for (let i = 0; i < rows.length; i++) if (i >= last.length || rows[i] !== last[i]) {
2935
+ const patch = i < last.length ? rowPatch(last[i], rows[i]) : null;
2936
+ ops.push(patch ? [i, patch.p] : [i, rows[i]]);
2937
+ html.push(rows[i]);
2938
+ }
2939
+ if (ops.length >= rows.length) return null;
2940
+ return Object.defineProperty({
2857
2941
  n: rows.length,
2858
2942
  r: ops
2859
- } : null;
2943
+ }, ROW_HTML, {
2944
+ value: html
2945
+ });
2860
2946
  }
2861
2947
  function resolveHoleValue(hole) {
2862
2948
  const result = {
@@ -3222,6 +3308,71 @@ function attrNames(text) {
3222
3308
  while (m = re.exec(text)) names.push(m[1]);
3223
3309
  return names;
3224
3310
  }
3311
+ const ROW_HTML = Symbol.for("solid.rowHtml");
3312
+ const ROW_TOKEN = /<(\/?)([a-zA-Z][^\s/>]*)((?:[^>"']|"[^"]*"|'[^']*')*)>|<!--([\s\S]*?)-->/g;
3313
+ const ROW_VOID = /^(?:area|base|br|col|embed|hr|img|input|link|meta|source|track|wbr)$/i;
3314
+ const ROW_FOREIGN = /^(?:svg|math)$/i;
3315
+ const ROW_RAW = /^(?:script|style|textarea|title|template)$/i;
3316
+ const ROW_KEY = /\s_key(?:="[^"]*")?(?![^\s/])/;
3317
+ const rowKey = attrs => (ROW_KEY.exec(attrs) || [""])[0];
3318
+ const ROW_ENTITY = /&(?:amp|lt|gt|quot|#39);/g;
3319
+ const ROW_ENTITIES = {
3320
+ "&amp;": "&",
3321
+ "&lt;": "<",
3322
+ "&gt;": ">",
3323
+ "&quot;": '"',
3324
+ "&#39;": "'"
3325
+ };
3326
+ function rowText(text) {
3327
+ if (!text.includes("&")) return text;
3328
+ if (text.replace(ROW_ENTITY, "").includes("&")) return null;
3329
+ return text.replace(ROW_ENTITY, e => ROW_ENTITIES[e]);
3330
+ }
3331
+ const ROW_HASH_SEED = 0x811c9dc5;
3332
+ function rowPatch(a, b) {
3333
+ const ra = new RegExp(ROW_TOKEN);
3334
+ const rb = new RegExp(ROW_TOKEN);
3335
+ const p = [];
3336
+ const stack = [[-1, 0, false]];
3337
+ let el = -1;
3338
+ let h = ROW_HASH_SEED;
3339
+ let ia = 0;
3340
+ let ib = 0;
3341
+ for (;;) {
3342
+ const ma = ra.exec(a);
3343
+ const mb = rb.exec(b);
3344
+ const ta = a.slice(ia, ma ? ma.index : a.length);
3345
+ const tb = b.slice(ib, mb ? mb.index : b.length);
3346
+ const top = stack[stack.length - 1];
3347
+ if (ta !== tb) {
3348
+ const text = rowText(tb);
3349
+ if (text === null) return null;
3350
+ p.push([top[0], top[1], text]);
3351
+ }
3352
+ if (!ma || !mb) return !ma && !mb ? {
3353
+ p,
3354
+ h: h >>> 0
3355
+ } : null;
3356
+ ia = ra.lastIndex;
3357
+ ib = rb.lastIndex;
3358
+ if (ma[4] !== undefined || mb[4] !== undefined) {
3359
+ if (ma[4] !== mb[4]) return null;
3360
+ top[1]++;
3361
+ } else if (ma[1] !== mb[1] || ma[2] !== mb[2]) return null;else if (ROW_RAW.test(ma[2])) return null;else if (ma[1]) {
3362
+ if (stack.length === 1) return null;
3363
+ stack.pop();
3364
+ } else {
3365
+ el++;
3366
+ top[1]++;
3367
+ const foreign = top[2] || ROW_FOREIGN.test(ma[2]);
3368
+ if (ma[3] !== mb[3]) {
3369
+ if (foreign || rowKey(ma[3]) !== rowKey(mb[3])) return null;
3370
+ p.push([el, mb[3].replace(/\/$/, "")]);
3371
+ }
3372
+ if (!ROW_VOID.test(ma[2]) && !ma[3].endsWith("/")) stack.push([el, 0, foreign]);
3373
+ }
3374
+ }
3375
+ }
3225
3376
  function ssr(t) {
3226
3377
  const len = arguments.length;
3227
3378
  if (len === 1) return {
package/dist/web.dev.js CHANGED
@@ -101,10 +101,21 @@ function memo(fn) {
101
101
  }
102
102
 
103
103
  function reconcileArrays(parentNode, a, b, marker) {
104
+ let active = parentNode.moveBefore && parentNode.isConnected && document.activeElement;
105
+ if (active === document.body) active = null;
106
+ const slot = marker || parentNode;
107
+ const insert = (n, ref) => {
108
+ active && n.isConnected && n.contains(active) ? parentNode.moveBefore(n, ref) : parentNode.insertBefore(n, ref);
109
+ if (marker || n[$$SLOT]) n[$$SLOT] = slot;
110
+ };
111
+ if (!a.length) {
112
+ for (const n of b) insert(n, marker);
113
+ return;
114
+ }
104
115
  const isLive = n => {
105
116
  if (!n) return false;
106
117
  const tag = n[$$SLOT];
107
- return n.parentNode === parentNode && (!tag || tag === marker);
118
+ return n.parentNode === parentNode && (!tag || tag === slot);
108
119
  };
109
120
  let bLength = b.length,
110
121
  aEnd = a.length,
@@ -127,40 +138,21 @@ function reconcileArrays(parentNode, a, b, marker) {
127
138
  bEnd--;
128
139
  }
129
140
  if (aEnd === aStart) {
130
- let node;
131
- if (bEnd < bLength) {
132
- if (bStart && isLive(node = b[bStart - 1])) node = node.nextSibling;else {
133
- let k = bEnd;
134
- while (k < bLength && !isLive(b[k])) k++;
135
- node = k < bLength ? b[k] : after;
136
- }
137
- } else node = after;
138
- while (bStart < bEnd) {
139
- const n = b[bStart++];
140
- parentNode.insertBefore(n, node);
141
- if (marker) n[$$SLOT] = marker;
142
- }
141
+ let k = bEnd;
142
+ while (k < bLength && !isLive(b[k])) k++;
143
+ const node = k < bLength ? b[k] : after;
144
+ while (bStart < bEnd) insert(b[bStart++], node);
143
145
  } else if (bEnd === bStart) {
144
146
  while (aStart < aEnd) {
145
147
  const n = a[aStart++];
146
148
  if ((!map || !map.has(n)) && isLive(n)) n.remove();
147
149
  }
148
- } else if ((anchor = a[aStart]) === b[bEnd - 1] && b[bStart] === a[aEnd - 1] && anchor.parentNode === parentNode && (!(anchorTag = anchor[$$SLOT]) || anchorTag === marker)) {
149
- if (marker) {
150
- do {
151
- const n = a[--aEnd];
152
- parentNode.insertBefore(n, anchor);
153
- n[$$SLOT] = marker;
154
- bStart++;
155
- if (aStart >= aEnd - 1 || bStart >= bEnd) break;
156
- } while (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]);
157
- } else {
158
- do {
159
- parentNode.insertBefore(a[--aEnd], anchor);
160
- bStart++;
161
- if (aStart >= aEnd - 1 || bStart >= bEnd) break;
162
- } while (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]);
163
- }
150
+ } else if ((anchor = a[aStart]) === b[bEnd - 1] && b[bStart] === a[aEnd - 1] && anchor.parentNode === parentNode && (!(anchorTag = anchor[$$SLOT]) || anchorTag === slot)) {
151
+ do {
152
+ insert(a[--aEnd], anchor);
153
+ bStart++;
154
+ if (aStart >= aEnd - 1 || bStart >= bEnd) break;
155
+ } while (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]);
164
156
  } else {
165
157
  if (!isLive(a[aStart])) {
166
158
  aStart++;
@@ -183,15 +175,12 @@ function reconcileArrays(parentNode, a, b, marker) {
183
175
  }
184
176
  if (sequence > index - bStart) {
185
177
  const node = a[aStart];
186
- while (bStart < index) {
187
- const n = b[bStart++];
188
- parentNode.insertBefore(n, node);
189
- if (marker) n[$$SLOT] = marker;
190
- }
178
+ while (bStart < index) insert(b[bStart++], node);
191
179
  } else {
192
- const newNode = b[bStart++];
193
- parentNode.replaceChild(newNode, a[aStart++]);
194
- if (marker) newNode[$$SLOT] = marker;
180
+ const newNode = b[bStart++],
181
+ node = a[aStart++];
182
+ active && parentNode.contains(active) ? insert(newNode, node) : parentNode.replaceChild(newNode, node);
183
+ if (marker || newNode[$$SLOT]) newNode[$$SLOT] = slot;
195
184
  }
196
185
  } else aStart++;
197
186
  } else a[aStart++].remove();
@@ -1540,7 +1529,7 @@ function gateHeadResource(props) {
1540
1529
  if (attrs) descriptor.attrs = attrs;
1541
1530
  effect(() => {
1542
1531
  const entry = warmAsset(descriptor);
1543
- if (gateable && !sharedConfig.hydrating && entry.loadState === "pending" && typeof waitAsset === "function") waitAsset(entry.loadPromise);
1532
+ if (gateable && !isHydrating() && entry.loadState === "pending" && typeof waitAsset === "function") waitAsset(entry.loadPromise);
1544
1533
  }, () => acquireAsset(descriptor));
1545
1534
  }
1546
1535
  function useHead(tags) {
@@ -1735,14 +1724,13 @@ function hydrate(code, element, options = {}) {
1735
1724
  }
1736
1725
  }
1737
1726
  function getNextElement(template) {
1738
- let node,
1739
- key,
1740
- hydrating = isHydrating();
1741
- if (!hydrating || !(node = sharedConfig.registry.get(key = getHydrationKey()))) {
1727
+ let key = sharedConfig.hydrating && getHydrationKey(),
1728
+ node = isHydrating() && sharedConfig.registry.get(key);
1729
+ if (!node) {
1742
1730
  if (!template) {
1743
1731
  throw new Error(`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${key}`);
1744
1732
  }
1745
- if (hydrating) {
1733
+ if (isHydrating()) {
1746
1734
  hydrationKeyMisses++;
1747
1735
  console.warn(`Hydration key miss for "${key}": no server-rendered element carries this key` + (template._html ? ` (template: ${template._html.slice(0, 60)})` : "") + `. A detached element was created instead; its subtree will not appear in the ` + `document or become interactive. This usually means the server and client ` + `hydration id namespaces are misaligned — when hydrating a subtree of a larger ` + `server render, wrap the document shell in <NoHydration> and re-enter with ` + `<Hydration> around the hydrated subtree (or pass hydrate() a renderId matching ` + `the server's <Hydration id>).`);
1748
1736
  }
@@ -1864,6 +1852,7 @@ function runHydrationEvents() {
1864
1852
  matches.sort((a, b) => a.distance - b.distance);
1865
1853
  for (let i = 0; i < matches.length; i++) eventHandler(e, matches[i].container, matches[i].state);
1866
1854
  } else if (matchContainer) eventHandler(e, matchContainer, matchState);
1855
+ flush();
1867
1856
  }
1868
1857
  if (sharedConfig.done) {
1869
1858
  sharedConfig.events = _$HY.events = null;
@@ -1980,7 +1969,6 @@ function eventHandler(e, container, state) {
1980
1969
  e[$$EVENT_OWNER] = owner;
1981
1970
  let node = resumeNode || e.target;
1982
1971
  const key = EVENT_KEY + e.type;
1983
- const oriTarget = e.target;
1984
1972
  const retarget = value => Object.defineProperty(e, "target", {
1985
1973
  configurable: true,
1986
1974
  value
@@ -2029,7 +2017,8 @@ function eventHandler(e, container, state) {
2029
2017
  } else walkUpTree();
2030
2018
  }
2031
2019
  else walkUpTree();
2032
- retarget(oriTarget);
2020
+ delete e.target;
2021
+ delete e.currentTarget;
2033
2022
  }
2034
2023
  function insertExpression(parent, value, current, marker) {
2035
2024
  tagElement(parent);
@@ -2075,7 +2064,7 @@ function insertExpression(parent, value, current, marker) {
2075
2064
  } else {
2076
2065
  parent.appendChild(value);
2077
2066
  }
2078
- if (marker) value[$$SLOT] = marker;
2067
+ if (marker || value[$$SLOT]) value[$$SLOT] = marker || parent;
2079
2068
  } else if (Array.isArray(value)) {
2080
2069
  const currentArray = Array.isArray(current);
2081
2070
  for (let i = 0, len = value.length; i < len; i++) {
@@ -2092,12 +2081,10 @@ function insertExpression(parent, value, current, marker) {
2092
2081
  if (value.length === 0) {
2093
2082
  cleanChildren(parent, current, marker);
2094
2083
  } else if (currentArray) {
2095
- if (current.length === 0) {
2096
- appendNodes(parent, value, marker);
2097
- } else reconcileArrays(parent, current, value, marker);
2084
+ reconcileArrays(parent, current, value, marker);
2098
2085
  } else {
2099
2086
  if (current != null) cleanChildren(parent, current);
2100
- appendNodes(parent, value);
2087
+ reconcileArrays(parent, [], value);
2101
2088
  }
2102
2089
  } else devCheck({
2103
2090
  code: "UNRECOGNIZED_INSERT_VALUE",
@@ -2125,18 +2112,19 @@ function writeSelectValue(node, value) {
2125
2112
  return queueMicrotask(() => node.value = value) || (node.value = value);
2126
2113
  }
2127
2114
  node._$v = value;
2128
- (selectInsert ||= p => {
2129
- p && p._$v == null && (p = p.parentNode);
2130
- const v = p && p._$v;
2131
- if (v == null) return;
2132
- if (v.map) {
2133
- const o = [...p.options];
2134
- for (let i = 0; i < o.length; i++) o[i].selected = v.some(x => x == o[i].value);
2135
- v.every(x => o.some(el => el.value == x)) && selectChange(p);
2136
- } else p.value = v, p.selectedIndex > -1 && p.value == v && (p._$v = null);
2137
- })(node);
2115
+ (selectInsert ||= applySelectValue)(node);
2138
2116
  queueMicrotask(() => selectInsert(node));
2139
2117
  }
2118
+ function applySelectValue(p) {
2119
+ p && p._$v == null && (p = p.parentNode);
2120
+ const v = p && p._$v;
2121
+ if (v == null) return;
2122
+ if (v.map) {
2123
+ const o = [...p.options];
2124
+ for (let i = 0; i < o.length; i++) o[i].selected = v.some(x => x == o[i].value);
2125
+ v.every(x => o.some(el => el.value == x)) && selectChange(p);
2126
+ } else p.value = v, p.selectedIndex > -1 && p.value == v && (p._$v = null);
2127
+ }
2140
2128
  function normalize(value, current, multi, doNotUnwrap) {
2141
2129
  value = flatten(value, {
2142
2130
  skipNonRendered: true,
@@ -2165,13 +2153,6 @@ function tagHost(value, host) {
2165
2153
  });
2166
2154
  }
2167
2155
  }
2168
- function appendNodes(parent, array, marker = null) {
2169
- for (let i = 0, len = array.length; i < len; i++) {
2170
- const n = array[i];
2171
- parent.insertBefore(n, marker);
2172
- if (marker) n[$$SLOT] = marker;
2173
- }
2174
- }
2175
2156
  function ownsAllChildren(parent, current) {
2176
2157
  if (current == null) return true;
2177
2158
  if (Array.isArray(current)) {
@@ -2206,12 +2187,12 @@ function cleanChildren(parent, current, marker, replacement) {
2206
2187
  const el = current[i];
2207
2188
  if (replacement !== el) {
2208
2189
  const tag = el[$$SLOT];
2209
- const owns = el.parentNode === parent && (!tag || tag === marker);
2190
+ const owns = el.parentNode === parent && (!tag || tag === (marker || parent));
2210
2191
  if (replacement && !inserted && !i) owns ? parent.replaceChild(replacement, el) : parent.insertBefore(replacement, marker);else if (owns) el.remove();
2211
2192
  } else inserted = true;
2212
2193
  }
2213
2194
  } else if (replacement) parent.insertBefore(replacement, marker);
2214
- if (replacement && marker) replacement[$$SLOT] = marker;
2195
+ if (replacement && (marker || replacement[$$SLOT])) replacement[$$SLOT] = marker || parent;
2215
2196
  }
2216
2197
  function gatherHydratable(element, root) {
2217
2198
  const templates = element.querySelectorAll(root ? `[_hk^="${root.replace(/["\\]/g, "\\$&")}"]` : `*[_hk]`);
@@ -2468,7 +2449,8 @@ function dynamic(source, options) {
2468
2449
  }
2469
2450
  function staticElement(tag, props) {
2470
2451
  const hydrating = sharedConfig.hydrating;
2471
- const el = hydrating ? getNextElement() : createElement(tag, untrack(() => props.is), untrack(() => props.xmlns));
2452
+ const create = () => createElement(tag, untrack(() => props.is), untrack(() => props.xmlns));
2453
+ const el = hydrating ? getNextElement(create) : create();
2472
2454
  spread(el, props);
2473
2455
  if (hydrating) runHydrationEvents();
2474
2456
  return el;