@krate/runtime 0.5.0-rc.11 → 0.5.0-rc.12

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.
@@ -36,4 +36,11 @@ export declare function createReactCompatExtras(c: any, options: any): ReactComp
36
36
  * client builds call it from their `react` module, once per Preact instance.
37
37
  */
38
38
  export declare function installDiscreteEffects(options: any): void;
39
+ /**
40
+ * The vnodes whose diff has started and not finished, kept in
41
+ * options.__krateOpen (the compiler's shared preact/hooks module installs the
42
+ * same tracker). It is empty between renders. __b is Preact's diff hook; a
43
+ * vnode whose render throws gets __e (the error hook) instead of diffed.
44
+ */
45
+ export declare function trackRenders(options: any): Set<unknown>;
39
46
  export {};
@@ -348,12 +348,46 @@ export function installDiscreteEffects(options) {
348
348
  raf = requestAnimationFrame(done);
349
349
  };
350
350
  // options._commit (mangled __c) runs after refs and, through preact/hooks'
351
- // own wrapper, after layout effects.
351
+ // own wrapper, after layout effects. Only a commit that ends a render
352
+ // flushes: a portal commits while its parent's render is still running, and
353
+ // the queue then holds the effects of components rendered earlier in that
354
+ // pass, whose layout and insertion effects have not run yet.
355
+ const open = trackRenders(options);
352
356
  const prevCommit = options.__c;
353
357
  options.__c = (vnode, queue) => {
354
358
  if (prevCommit)
355
359
  prevCommit(vnode, queue);
356
- if (discrete && flushEffects)
360
+ if (discrete && flushEffects && open.size === 0)
357
361
  flushEffects();
358
362
  };
359
363
  }
364
+ /**
365
+ * The vnodes whose diff has started and not finished, kept in
366
+ * options.__krateOpen (the compiler's shared preact/hooks module installs the
367
+ * same tracker). It is empty between renders. __b is Preact's diff hook; a
368
+ * vnode whose render throws gets __e (the error hook) instead of diffed.
369
+ */
370
+ export function trackRenders(options) {
371
+ if (options.__krateOpen)
372
+ return options.__krateOpen;
373
+ const open = new Set();
374
+ options.__krateOpen = open;
375
+ const prevDiff = options.__b;
376
+ const prevDiffed = options.diffed;
377
+ const prevError = options.__e;
378
+ options.__b = (vnode) => {
379
+ open.add(vnode);
380
+ if (prevDiff)
381
+ prevDiff(vnode);
382
+ };
383
+ options.diffed = (vnode) => {
384
+ open.delete(vnode);
385
+ if (prevDiffed)
386
+ prevDiffed(vnode);
387
+ };
388
+ options.__e = function (error, vnode, ...rest) {
389
+ open.delete(vnode);
390
+ return prevError.call(this, error, vnode, ...rest);
391
+ };
392
+ return open;
393
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krate/runtime",
3
- "version": "0.5.0-rc.11",
3
+ "version": "0.5.0-rc.12",
4
4
  "description": "Client-side runtime for Krate - signals, hydration, SPA router, resources, and context.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",