@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.
@@ -224,26 +224,12 @@ function resolveCodecOptions(options = {}) {
224
224
  }
225
225
 
226
226
  const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : Feature.ErrorPrototypeStack;
227
- function createJSONSerializer({
228
- onData,
229
- onDone,
230
- onError,
231
- plugins,
232
- disabledFeatures,
233
- depthLimit,
234
- serializeErrorStacks
235
- }) {
236
- const resolved = resolveCodecOptions({
237
- plugins,
238
- disabledFeatures,
239
- depthLimit,
240
- serializeErrorStacks
241
- });
242
- const refs = new Map();
227
+ function createKeyedSerializer(serialize, onError, onDone) {
243
228
  const cancels = new Set();
244
229
  let pendingWrites = 0;
245
230
  let flushed = false;
246
231
  let done = false;
232
+ let closed = false;
247
233
  const maybeDone = () => {
248
234
  if (flushed && pendingWrites === 0 && !done) {
249
235
  done = true;
@@ -255,42 +241,90 @@ function createJSONSerializer({
255
241
  if (flushed) return;
256
242
  pendingWrites++;
257
243
  let settled = false;
244
+ let failed = false;
245
+ let started = false;
258
246
  let cancel = null;
259
- const stream = toCrossJSONStream(value, {
260
- refs,
261
- plugins: resolved.plugins,
262
- disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(resolved.serializeErrorStacks),
263
- onParse(node, initial) {
264
- onData({
265
- key,
266
- node,
267
- initial
268
- });
269
- },
270
- onError,
271
- onDone() {
272
- settled = true;
273
- if (cancel) cancels.delete(cancel);
274
- pendingWrites--;
275
- maybeDone();
276
- }
277
- });
278
- if (!settled) {
279
- cancel = stream;
280
- cancels.add(cancel);
247
+ const settle = () => {
248
+ if (settled) return;
249
+ settled = true;
250
+ if (cancel) cancels.delete(cancel);
251
+ pendingWrites--;
252
+ maybeDone();
253
+ };
254
+ let stream;
255
+ try {
256
+ stream = serialize(key, value, {
257
+ onError: onError && (err => {
258
+ failed = true;
259
+ onError(err);
260
+ if (cancel) {
261
+ cancel();
262
+ settle();
263
+ }
264
+ }),
265
+ onDone: settle
266
+ }, initial => {
267
+ if (initial) started = true;
268
+ return !closed;
269
+ });
270
+ } catch (err) {
271
+ settle();
272
+ throw err;
273
+ }
274
+ if (settled) return;
275
+ if (closed || failed) {
276
+ stream();
277
+ settle();
278
+ return;
281
279
  }
280
+ cancel = stream;
281
+ cancels.add(cancel);
282
282
  },
283
283
  flush() {
284
284
  flushed = true;
285
285
  maybeDone();
286
286
  },
287
287
  close() {
288
- flushed = true;
288
+ closed = flushed = true;
289
289
  for (const cancel of cancels) cancel();
290
290
  cancels.clear();
291
+ if (!done) {
292
+ done = true;
293
+ onDone && onDone();
294
+ }
291
295
  }
292
296
  };
293
297
  }
298
+ function createJSONSerializer({
299
+ onData,
300
+ onDone,
301
+ onError,
302
+ plugins,
303
+ disabledFeatures,
304
+ depthLimit,
305
+ serializeErrorStacks
306
+ }) {
307
+ const resolved = resolveCodecOptions({
308
+ plugins,
309
+ disabledFeatures,
310
+ depthLimit,
311
+ serializeErrorStacks
312
+ });
313
+ const refs = new Map();
314
+ return createKeyedSerializer((key, value, callbacks, live) => toCrossJSONStream(value, {
315
+ refs,
316
+ plugins: resolved.plugins,
317
+ disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(resolved.serializeErrorStacks),
318
+ onParse(node, initial) {
319
+ if (live(initial)) onData({
320
+ key,
321
+ node,
322
+ initial
323
+ });
324
+ },
325
+ ...callbacks
326
+ }), onError, onDone);
327
+ }
294
328
 
295
329
  function records() {
296
330
  return undefined;
@@ -466,6 +500,7 @@ const stripHoleMarkers = html => html.replace(/<!--lh:\/?\d+-->/g, "");
466
500
  function frameSkeleton(html) {
467
501
  return html.replace(HOLE_RANGE, "<!--lh:$1--><!--lh:/$1-->").replace(SLOT_RANGE, "<!--slot:$1:start--><!--slot:$1:end-->");
468
502
  }
503
+ const ROW_HTML = Symbol.for("solid.rowHtml");
469
504
  function holeDigests(html, attrText, into = {}) {
470
505
  for (const m of html.matchAll(HOLE_RANGE)) {
471
506
  into["lh:" + m[1]] = textDigest(stripHoleMarkers(m[2]));
@@ -798,7 +833,7 @@ function createFrameSink(write, frame, have, hooks) {
798
833
  record.rows = rows;
799
834
  record.base = base;
800
835
  } else record.value = source;
801
- withHoles(record, holeDigests(record.rows ? rows.r.map(r => r[1]).join("") : source, null));
836
+ withHoles(record, holeDigests(record.rows ? (rows[ROW_HTML] || rows.r.map(r => r[1])).join("") : source, null));
802
837
  if (record.rows && hooks && hooks.retain) record[HOLE_SOURCE] = withHoles({
803
838
  kind: "html",
804
839
  value: source,
@@ -224,26 +224,12 @@ function resolveCodecOptions(options = {}) {
224
224
  }
225
225
 
226
226
  const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : Feature.ErrorPrototypeStack;
227
- function createJSONSerializer({
228
- onData,
229
- onDone,
230
- onError,
231
- plugins,
232
- disabledFeatures,
233
- depthLimit,
234
- serializeErrorStacks
235
- }) {
236
- const resolved = resolveCodecOptions({
237
- plugins,
238
- disabledFeatures,
239
- depthLimit,
240
- serializeErrorStacks
241
- });
242
- const refs = new Map();
227
+ function createKeyedSerializer(serialize, onError, onDone) {
243
228
  const cancels = new Set();
244
229
  let pendingWrites = 0;
245
230
  let flushed = false;
246
231
  let done = false;
232
+ let closed = false;
247
233
  const maybeDone = () => {
248
234
  if (flushed && pendingWrites === 0 && !done) {
249
235
  done = true;
@@ -255,42 +241,90 @@ function createJSONSerializer({
255
241
  if (flushed) return;
256
242
  pendingWrites++;
257
243
  let settled = false;
244
+ let failed = false;
245
+ let started = false;
258
246
  let cancel = null;
259
- const stream = toCrossJSONStream(value, {
260
- refs,
261
- plugins: resolved.plugins,
262
- disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(resolved.serializeErrorStacks),
263
- onParse(node, initial) {
264
- onData({
265
- key,
266
- node,
267
- initial
268
- });
269
- },
270
- onError,
271
- onDone() {
272
- settled = true;
273
- if (cancel) cancels.delete(cancel);
274
- pendingWrites--;
275
- maybeDone();
276
- }
277
- });
278
- if (!settled) {
279
- cancel = stream;
280
- cancels.add(cancel);
247
+ const settle = () => {
248
+ if (settled) return;
249
+ settled = true;
250
+ if (cancel) cancels.delete(cancel);
251
+ pendingWrites--;
252
+ maybeDone();
253
+ };
254
+ let stream;
255
+ try {
256
+ stream = serialize(key, value, {
257
+ onError: onError && (err => {
258
+ failed = true;
259
+ onError(err);
260
+ if (cancel) {
261
+ cancel();
262
+ settle();
263
+ }
264
+ }),
265
+ onDone: settle
266
+ }, initial => {
267
+ if (initial) started = true;
268
+ return !closed;
269
+ });
270
+ } catch (err) {
271
+ settle();
272
+ throw err;
273
+ }
274
+ if (settled) return;
275
+ if (closed || failed) {
276
+ stream();
277
+ settle();
278
+ return;
281
279
  }
280
+ cancel = stream;
281
+ cancels.add(cancel);
282
282
  },
283
283
  flush() {
284
284
  flushed = true;
285
285
  maybeDone();
286
286
  },
287
287
  close() {
288
- flushed = true;
288
+ closed = flushed = true;
289
289
  for (const cancel of cancels) cancel();
290
290
  cancels.clear();
291
+ if (!done) {
292
+ done = true;
293
+ onDone && onDone();
294
+ }
291
295
  }
292
296
  };
293
297
  }
298
+ function createJSONSerializer({
299
+ onData,
300
+ onDone,
301
+ onError,
302
+ plugins,
303
+ disabledFeatures,
304
+ depthLimit,
305
+ serializeErrorStacks
306
+ }) {
307
+ const resolved = resolveCodecOptions({
308
+ plugins,
309
+ disabledFeatures,
310
+ depthLimit,
311
+ serializeErrorStacks
312
+ });
313
+ const refs = new Map();
314
+ return createKeyedSerializer((key, value, callbacks, live) => toCrossJSONStream(value, {
315
+ refs,
316
+ plugins: resolved.plugins,
317
+ disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(resolved.serializeErrorStacks),
318
+ onParse(node, initial) {
319
+ if (live(initial)) onData({
320
+ key,
321
+ node,
322
+ initial
323
+ });
324
+ },
325
+ ...callbacks
326
+ }), onError, onDone);
327
+ }
294
328
 
295
329
  const RECORDS = Symbol.for("@solidjs/signals/observe/records");
296
330
  function records() {
@@ -467,6 +501,7 @@ const stripHoleMarkers = html => html.replace(/<!--lh:\/?\d+-->/g, "");
467
501
  function frameSkeleton(html) {
468
502
  return html.replace(HOLE_RANGE, "<!--lh:$1--><!--lh:/$1-->").replace(SLOT_RANGE, "<!--slot:$1:start--><!--slot:$1:end-->");
469
503
  }
504
+ const ROW_HTML = Symbol.for("solid.rowHtml");
470
505
  function holeDigests(html, attrText, into = {}) {
471
506
  for (const m of html.matchAll(HOLE_RANGE)) {
472
507
  into["lh:" + m[1]] = textDigest(stripHoleMarkers(m[2]));
@@ -799,7 +834,7 @@ function createFrameSink(write, frame, have, hooks) {
799
834
  record.rows = rows;
800
835
  record.base = base;
801
836
  } else record.value = source;
802
- withHoles(record, holeDigests(record.rows ? rows.r.map(r => r[1]).join("") : source, null));
837
+ withHoles(record, holeDigests(record.rows ? (rows[ROW_HTML] || rows.r.map(r => r[1])).join("") : source, null));
803
838
  if (record.rows && hooks && hooks.retain) record[HOLE_SOURCE] = withHoles({
804
839
  kind: "html",
805
840
  value: source,
@@ -391,7 +391,7 @@ function connect(response, wire, address, binding, host, bump, begin) {
391
391
  });
392
392
  return binding;
393
393
  }
394
- function rows(open, close, ops, parse, morph) {
394
+ function rows(open, close, ops, parse, morph, claim) {
395
395
  const isRow = n => n.nodeType === 8 && n.data === "lr";
396
396
  const starts = [];
397
397
  for (let n = open.nextSibling; n && n !== close; n = n.nextSibling) {
@@ -405,29 +405,125 @@ function rows(open, close, ops, parse, morph) {
405
405
  let appended = 0;
406
406
  for (const [i] of ops.r) if (i >= had) appended++;
407
407
  if (!had || appended !== Math.max(0, n - had)) return false;
408
- const fragment = parse(ops.r.map(op => "<!--lr-->" + op[1]).join(""));
408
+ const rowEnd = i => i + 1 < Math.min(n, had) ? starts[i + 1] : close;
409
+ const patched = [];
410
+ let html = "";
411
+ let whole = 0;
412
+ for (const op of ops.r) {
413
+ if (typeof op[1] === "string") {
414
+ html += "<!--lr-->" + op[1];
415
+ whole++;
416
+ patched.push(null);
417
+ continue;
418
+ }
419
+ if (op[0] >= had) return false;
420
+ const els = rowElements(starts[op[0]], rowEnd(op[0]), op[2]);
421
+ if (!els) return false;
422
+ for (const edit of op[1]) if (edit[0] >= els.length) return false;
423
+ patched.push(els);
424
+ }
409
425
  const parsed = [];
410
- for (let c = fragment.firstChild; c;) {
411
- const next = c.nextSibling;
412
- if (isRow(c)) parsed.push(document.createDocumentFragment());else parsed[parsed.length - 1].appendChild(c);
413
- c = next;
426
+ if (whole) {
427
+ const fragment = parse(html);
428
+ for (let c = fragment.firstChild; c;) {
429
+ const next = c.nextSibling;
430
+ if (isRow(c)) parsed.push(document.createDocumentFragment());else parsed[parsed.length - 1].appendChild(c);
431
+ c = next;
432
+ }
433
+ if (parsed.length !== whole) return false;
414
434
  }
415
- if (parsed.length !== ops.r.length) return false;
416
435
  const parent = open.parentNode;
417
436
  if (n < had) while (starts[n].nextSibling !== close) parent.removeChild(close.previousSibling);
418
437
  if (n < had) parent.removeChild(starts[n]);
419
- ops.r.forEach(([i], k) => {
420
- if (i < had) {
421
- const end = i + 1 < Math.min(n, had) ? starts[i + 1] : close;
422
- morph(starts[i], end, parsed[k]);
423
- } else {
438
+ let k = 0;
439
+ ops.r.forEach((op, j) => {
440
+ const i = op[0];
441
+ const els = patched[j];
442
+ if (els) return patchRow(starts[i], rowEnd(i), els, op[1], claim);
443
+ const fragment = parsed[k++];
444
+ if (i < had) morph(starts[i], rowEnd(i), fragment);else {
424
445
  const marker = document.createComment("lr");
425
446
  parent.insertBefore(marker, close);
426
- parent.insertBefore(parsed[k], close);
447
+ parent.insertBefore(fragment, close);
427
448
  }
428
449
  });
429
450
  return true;
430
451
  }
452
+ function rowElements(start, end, shape) {
453
+ const els = [];
454
+ let h = 0x811c9dc5;
455
+ const walk = (n, stop, parent) => {
456
+ for (; n && n !== stop; n = n.nextSibling) {
457
+ if (n.nodeType === 8 && /^lh:/.test(n.data)) return false;
458
+ if (n.nodeType !== 1) continue;
459
+ const el = els.length;
460
+ if (shape !== undefined) {
461
+ const tag = n.localName;
462
+ for (let i = 0; i < tag.length; i++) h = Math.imul(h ^ (tag.charCodeAt(i) | 32), 16777619);
463
+ h = Math.imul(h ^ parent + 2, 16777619);
464
+ }
465
+ els.push(n);
466
+ if (!walk(n.firstChild, null, el)) return false;
467
+ }
468
+ return true;
469
+ };
470
+ if (!walk(start.nextSibling, end, -1)) return null;
471
+ if (shape !== undefined && h >>> 0 !== shape) {
472
+ console.error("A live row's markup doesn't parse to the elements the server rendered (invalid HTML nesting?); the row was re-sent whole.", start.nextSibling);
473
+ return null;
474
+ }
475
+ return els;
476
+ }
477
+ const ATTR = /\s([^\s=/>"']+)(?:="([^"]*)")?/g;
478
+ const ATTR_ENTITY = /&(?:amp|lt|gt|quot|#39);/g;
479
+ const ATTR_ENTITIES = {
480
+ "&amp;": "&",
481
+ "&lt;": "<",
482
+ "&gt;": ">",
483
+ "&quot;": '"',
484
+ "&#39;": "'"
485
+ };
486
+ function attrArea(text) {
487
+ if (/=[^"]/.test(text) || text.replace(ATTR_ENTITY, "").includes("&")) return parseFragment(`<i${text}></i>`).firstChild;
488
+ const attributes = [];
489
+ const names = new Set();
490
+ for (const m of text.matchAll(ATTR)) {
491
+ const value = m[2] === undefined ? "" : m[2].replace(ATTR_ENTITY, e => ATTR_ENTITIES[e]);
492
+ const name = m[1].toLowerCase();
493
+ attributes.push({
494
+ name,
495
+ value
496
+ });
497
+ names.add(name);
498
+ }
499
+ return {
500
+ attributes,
501
+ hasAttribute: name => names.has(name)
502
+ };
503
+ }
504
+ function patchRow(start, end, els, patch, claim) {
505
+ for (const op of patch) {
506
+ const el = op[0] < 0 ? null : els[op[0]];
507
+ if (el && el.closest("[data-preserve]")) continue;
508
+ if (op.length === 2) {
509
+ morphAttributes(el, attrArea(op[1]), claim);
510
+ continue;
511
+ }
512
+ let seen = 0;
513
+ let at = el ? el.firstChild : start.nextSibling;
514
+ const stop = el ? null : end;
515
+ let text = null;
516
+ for (; at && at !== stop; at = at.nextSibling) {
517
+ if (at.nodeType === 3) {
518
+ if (seen === op[1]) {
519
+ text = at;
520
+ break;
521
+ }
522
+ } else if (seen++ === op[1]) break;
523
+ }
524
+ if (text) text.data = op[2];else if (op[2]) (el || start.parentNode).insertBefore(document.createTextNode(op[2]), at);
525
+ }
526
+ }
431
527
  function hole(f, marker, record, index) {
432
528
  const open = target(f, "hole:" + marker, n => n.nodeType === 8 && n.data === marker);
433
529
  if (!open) return false;
@@ -437,7 +533,7 @@ function hole(f, marker, record, index) {
437
533
  return false;
438
534
  }
439
535
  if (record.rows) {
440
- if (f.s()[marker] !== record.base || !rows(open, close, record.rows, parseFragment, (start, end, fragment) => reconcileChildren(start.parentNode, fragment, start, end, f.c))) {
536
+ if (f.s()[marker] !== record.base || !rows(open, close, record.rows, parseFragment, (start, end, fragment) => reconcileChildren(start.parentNode, fragment, start, end, f.c), f.c)) {
441
537
  f.x("hole:" + marker, record);
442
538
  return false;
443
539
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@solidjs/web",
3
3
  "description": "Solid's web runtime: client rendering, hydration, SSR, and DOM-specific control flow (Portal, Dynamic).",
4
- "version": "2.0.0-rc.17",
4
+ "version": "2.0.0-rc.19",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -373,11 +373,11 @@
373
373
  "test-types": "tsc --project tsconfig.test.json && tsc --project tsconfig.test.augment.json"
374
374
  },
375
375
  "dependencies": {
376
- "seroval": "1.6.7",
377
- "seroval-plugins": "1.6.7"
376
+ "seroval": "1.7.0",
377
+ "seroval-plugins": "1.7.0"
378
378
  },
379
379
  "peerDependencies": {
380
- "solid-js": "^2.0.0-rc.17"
380
+ "solid-js": "^2.0.0-rc.19"
381
381
  },
382
382
  "devDependencies": {
383
383
  "@codspeed/vitest-plugin": "^5.4.0",
@@ -132,11 +132,16 @@ function createJSONDeserializer(options) {
132
132
  const close = () => {
133
133
  alive = false;
134
134
  };
135
- const off = stream.on({
136
- next() {},
137
- throw: close,
138
- return: close
139
- });
135
+ let off;
136
+ try {
137
+ off = stream.on({
138
+ next() {},
139
+ throw: close,
140
+ return: close
141
+ });
142
+ } catch {
143
+ return stream.alive !== false;
144
+ }
140
145
  if (typeof off === "function") off();
141
146
  return alive;
142
147
  }