@async/framework 0.11.11 → 0.11.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.
package/browser.ts CHANGED
@@ -5816,101 +5816,25 @@ const __boundaryReceiverModule = (() => {
5816
5816
 
5817
5817
  const normalized = validatePatch(patch);
5818
5818
  const record = boundaryRecord(normalized.boundary);
5819
- if (normalized.seq <= record.lastSeq) {
5820
- const result = {
5821
- status: "ignored-stale",
5822
- boundary: normalized.boundary,
5823
- seq: normalized.seq,
5824
- lastSeq: record.lastSeq
5825
- };
5826
- record.ignored += 1;
5827
- record.lastStatus = result.status;
5828
- remember(result);
5829
- onIgnore?.(result, patch);
5830
- return result;
5831
- }
5832
-
5833
- if (normalized.parentScope !== undefined && isScopeDestroyed(normalized.parentScope)) {
5834
- const result = {
5835
- status: "ignored-destroyed",
5836
- boundary: normalized.boundary,
5837
- seq: normalized.seq,
5838
- parentScope: normalized.parentScope
5839
- };
5840
- record.ignored += 1;
5841
- record.lastStatus = result.status;
5842
- remember(result);
5843
- onIgnore?.(result, patch);
5844
- return result;
5845
- }
5846
-
5847
- record.lastSeq = normalized.seq;
5848
-
5849
- if (Object.hasOwn(normalized, "error")) {
5850
- const error = toStableError(normalized.error);
5851
- const result = {
5852
- status: "errored",
5853
- boundary: normalized.boundary,
5854
- seq: normalized.seq,
5855
- error
5856
- };
5857
- record.errored += 1;
5858
- record.lastStatus = result.status;
5859
- remember(result);
5860
- onError?.(error, result, patch);
5861
- if (throwOnError) {
5862
- throw error;
5863
- }
5864
- return result;
5865
- }
5819
+ let releasePending;
5820
+ const previousPending = record.pending ?? Promise.resolve();
5821
+ const pending = new Promise((resolve) => {
5822
+ releasePending = resolve;
5823
+ });
5824
+ record.pending = pending;
5866
5825
 
5867
- if (normalized.signals) {
5868
- if (!signals || typeof signals.set !== "function") {
5869
- throw new Error("Boundary patch includes signals, but no signal registry is available.");
5870
- }
5871
- for (const [path, value] of Object.entries(normalized.signals)) {
5872
- signals.set(path, value);
5826
+ try {
5827
+ await previousPending;
5828
+ if (destroyed) {
5829
+ throw new Error("Boundary receiver has been destroyed.");
5873
5830
  }
5874
- }
5875
-
5876
- if (normalized.cache?.browser) {
5877
- if (!cache || typeof cache.restore !== "function") {
5878
- throw new Error("Boundary patch includes browser cache, but no cache registry is available.");
5831
+ return await applyBoundaryPatch(record, normalized, patch);
5832
+ } finally {
5833
+ releasePending();
5834
+ if (record.pending === pending) {
5835
+ record.pending = undefined;
5879
5836
  }
5880
- cache.restore(normalized.cache.browser);
5881
- }
5882
-
5883
- if (normalized.html != null) {
5884
- loader.swap(normalized.boundary, normalized.html);
5885
- }
5886
-
5887
- await flushScheduler(scheduler, normalized.scope);
5888
-
5889
- if (normalized.redirect) {
5890
- await followRedirect(normalized.redirect, router, loader);
5891
- const result = {
5892
- status: "redirected",
5893
- boundary: normalized.boundary,
5894
- seq: normalized.seq,
5895
- redirect: normalized.redirect
5896
- };
5897
- record.applied += 1;
5898
- record.lastStatus = result.status;
5899
- remember(result);
5900
- onApply?.(result, patch);
5901
- return result;
5902
5837
  }
5903
-
5904
- const result = {
5905
- status: "applied",
5906
- boundary: normalized.boundary,
5907
- seq: normalized.seq
5908
- };
5909
- record.applied += 1;
5910
- record.lastStatus = result.status;
5911
- remember(result);
5912
- onApply?.(result, patch);
5913
- return result;
5914
5838
  },
5915
5839
 
5916
5840
  inspect() {
@@ -5958,6 +5882,105 @@ const __boundaryReceiverModule = (() => {
5958
5882
 
5959
5883
  return receiver;
5960
5884
 
5885
+ async function applyBoundaryPatch(record, normalized, patch) {
5886
+ if (normalized.seq <= record.lastSeq) {
5887
+ const result = {
5888
+ status: "ignored-stale",
5889
+ boundary: normalized.boundary,
5890
+ seq: normalized.seq,
5891
+ lastSeq: record.lastSeq
5892
+ };
5893
+ record.ignored += 1;
5894
+ record.lastStatus = result.status;
5895
+ remember(result);
5896
+ onIgnore?.(result, patch);
5897
+ return result;
5898
+ }
5899
+
5900
+ if (normalized.parentScope !== undefined && isScopeDestroyed(normalized.parentScope)) {
5901
+ const result = {
5902
+ status: "ignored-destroyed",
5903
+ boundary: normalized.boundary,
5904
+ seq: normalized.seq,
5905
+ parentScope: normalized.parentScope
5906
+ };
5907
+ record.ignored += 1;
5908
+ record.lastStatus = result.status;
5909
+ remember(result);
5910
+ onIgnore?.(result, patch);
5911
+ return result;
5912
+ }
5913
+
5914
+ if (Object.hasOwn(normalized, "error")) {
5915
+ const error = toStableError(normalized.error);
5916
+ const result = {
5917
+ status: "errored",
5918
+ boundary: normalized.boundary,
5919
+ seq: normalized.seq,
5920
+ error
5921
+ };
5922
+ record.lastSeq = normalized.seq;
5923
+ record.errored += 1;
5924
+ record.lastStatus = result.status;
5925
+ remember(result);
5926
+ onError?.(error, result, patch);
5927
+ if (throwOnError) {
5928
+ throw error;
5929
+ }
5930
+ return result;
5931
+ }
5932
+
5933
+ if (normalized.signals) {
5934
+ if (!signals || typeof signals.set !== "function") {
5935
+ throw new Error("Boundary patch includes signals, but no signal registry is available.");
5936
+ }
5937
+ for (const [path, value] of Object.entries(normalized.signals)) {
5938
+ signals.set(path, value);
5939
+ }
5940
+ }
5941
+
5942
+ if (normalized.cache?.browser) {
5943
+ if (!cache || typeof cache.restore !== "function") {
5944
+ throw new Error("Boundary patch includes browser cache, but no cache registry is available.");
5945
+ }
5946
+ cache.restore(normalized.cache.browser);
5947
+ }
5948
+
5949
+ if (normalized.html != null) {
5950
+ loader.swap(normalized.boundary, normalized.html);
5951
+ }
5952
+
5953
+ await flushScheduler(scheduler, normalized.scope);
5954
+
5955
+ if (normalized.redirect) {
5956
+ const result = {
5957
+ status: "redirected",
5958
+ boundary: normalized.boundary,
5959
+ seq: normalized.seq,
5960
+ redirect: normalized.redirect
5961
+ };
5962
+ await followRedirect(normalized.redirect, router, loader);
5963
+ record.applied += 1;
5964
+ record.lastSeq = normalized.seq;
5965
+ record.lastStatus = result.status;
5966
+ remember(result);
5967
+ onApply?.(result, patch);
5968
+ return result;
5969
+ }
5970
+
5971
+ const result = {
5972
+ status: "applied",
5973
+ boundary: normalized.boundary,
5974
+ seq: normalized.seq
5975
+ };
5976
+ record.applied += 1;
5977
+ record.lastSeq = normalized.seq;
5978
+ record.lastStatus = result.status;
5979
+ remember(result);
5980
+ onApply?.(result, patch);
5981
+ return result;
5982
+ }
5983
+
5961
5984
  function boundaryRecord(boundary) {
5962
5985
  if (!boundaries.has(boundary)) {
5963
5986
  boundaries.set(boundary, {
@@ -5965,7 +5988,8 @@ const __boundaryReceiverModule = (() => {
5965
5988
  applied: 0,
5966
5989
  ignored: 0,
5967
5990
  errored: 0,
5968
- lastStatus: undefined
5991
+ lastStatus: undefined,
5992
+ pending: undefined
5969
5993
  });
5970
5994
  }
5971
5995
  return boundaries.get(boundary);
package/browser.umd.js CHANGED
@@ -5826,101 +5826,25 @@
5826
5826
 
5827
5827
  const normalized = validatePatch(patch);
5828
5828
  const record = boundaryRecord(normalized.boundary);
5829
- if (normalized.seq <= record.lastSeq) {
5830
- const result = {
5831
- status: "ignored-stale",
5832
- boundary: normalized.boundary,
5833
- seq: normalized.seq,
5834
- lastSeq: record.lastSeq
5835
- };
5836
- record.ignored += 1;
5837
- record.lastStatus = result.status;
5838
- remember(result);
5839
- onIgnore?.(result, patch);
5840
- return result;
5841
- }
5842
-
5843
- if (normalized.parentScope !== undefined && isScopeDestroyed(normalized.parentScope)) {
5844
- const result = {
5845
- status: "ignored-destroyed",
5846
- boundary: normalized.boundary,
5847
- seq: normalized.seq,
5848
- parentScope: normalized.parentScope
5849
- };
5850
- record.ignored += 1;
5851
- record.lastStatus = result.status;
5852
- remember(result);
5853
- onIgnore?.(result, patch);
5854
- return result;
5855
- }
5856
-
5857
- record.lastSeq = normalized.seq;
5858
-
5859
- if (Object.hasOwn(normalized, "error")) {
5860
- const error = toStableError(normalized.error);
5861
- const result = {
5862
- status: "errored",
5863
- boundary: normalized.boundary,
5864
- seq: normalized.seq,
5865
- error
5866
- };
5867
- record.errored += 1;
5868
- record.lastStatus = result.status;
5869
- remember(result);
5870
- onError?.(error, result, patch);
5871
- if (throwOnError) {
5872
- throw error;
5873
- }
5874
- return result;
5875
- }
5829
+ let releasePending;
5830
+ const previousPending = record.pending ?? Promise.resolve();
5831
+ const pending = new Promise((resolve) => {
5832
+ releasePending = resolve;
5833
+ });
5834
+ record.pending = pending;
5876
5835
 
5877
- if (normalized.signals) {
5878
- if (!signals || typeof signals.set !== "function") {
5879
- throw new Error("Boundary patch includes signals, but no signal registry is available.");
5880
- }
5881
- for (const [path, value] of Object.entries(normalized.signals)) {
5882
- signals.set(path, value);
5836
+ try {
5837
+ await previousPending;
5838
+ if (destroyed) {
5839
+ throw new Error("Boundary receiver has been destroyed.");
5883
5840
  }
5884
- }
5885
-
5886
- if (normalized.cache?.browser) {
5887
- if (!cache || typeof cache.restore !== "function") {
5888
- throw new Error("Boundary patch includes browser cache, but no cache registry is available.");
5841
+ return await applyBoundaryPatch(record, normalized, patch);
5842
+ } finally {
5843
+ releasePending();
5844
+ if (record.pending === pending) {
5845
+ record.pending = undefined;
5889
5846
  }
5890
- cache.restore(normalized.cache.browser);
5891
- }
5892
-
5893
- if (normalized.html != null) {
5894
- loader.swap(normalized.boundary, normalized.html);
5895
- }
5896
-
5897
- await flushScheduler(scheduler, normalized.scope);
5898
-
5899
- if (normalized.redirect) {
5900
- await followRedirect(normalized.redirect, router, loader);
5901
- const result = {
5902
- status: "redirected",
5903
- boundary: normalized.boundary,
5904
- seq: normalized.seq,
5905
- redirect: normalized.redirect
5906
- };
5907
- record.applied += 1;
5908
- record.lastStatus = result.status;
5909
- remember(result);
5910
- onApply?.(result, patch);
5911
- return result;
5912
5847
  }
5913
-
5914
- const result = {
5915
- status: "applied",
5916
- boundary: normalized.boundary,
5917
- seq: normalized.seq
5918
- };
5919
- record.applied += 1;
5920
- record.lastStatus = result.status;
5921
- remember(result);
5922
- onApply?.(result, patch);
5923
- return result;
5924
5848
  },
5925
5849
 
5926
5850
  inspect() {
@@ -5968,6 +5892,105 @@
5968
5892
 
5969
5893
  return receiver;
5970
5894
 
5895
+ async function applyBoundaryPatch(record, normalized, patch) {
5896
+ if (normalized.seq <= record.lastSeq) {
5897
+ const result = {
5898
+ status: "ignored-stale",
5899
+ boundary: normalized.boundary,
5900
+ seq: normalized.seq,
5901
+ lastSeq: record.lastSeq
5902
+ };
5903
+ record.ignored += 1;
5904
+ record.lastStatus = result.status;
5905
+ remember(result);
5906
+ onIgnore?.(result, patch);
5907
+ return result;
5908
+ }
5909
+
5910
+ if (normalized.parentScope !== undefined && isScopeDestroyed(normalized.parentScope)) {
5911
+ const result = {
5912
+ status: "ignored-destroyed",
5913
+ boundary: normalized.boundary,
5914
+ seq: normalized.seq,
5915
+ parentScope: normalized.parentScope
5916
+ };
5917
+ record.ignored += 1;
5918
+ record.lastStatus = result.status;
5919
+ remember(result);
5920
+ onIgnore?.(result, patch);
5921
+ return result;
5922
+ }
5923
+
5924
+ if (Object.hasOwn(normalized, "error")) {
5925
+ const error = toStableError(normalized.error);
5926
+ const result = {
5927
+ status: "errored",
5928
+ boundary: normalized.boundary,
5929
+ seq: normalized.seq,
5930
+ error
5931
+ };
5932
+ record.lastSeq = normalized.seq;
5933
+ record.errored += 1;
5934
+ record.lastStatus = result.status;
5935
+ remember(result);
5936
+ onError?.(error, result, patch);
5937
+ if (throwOnError) {
5938
+ throw error;
5939
+ }
5940
+ return result;
5941
+ }
5942
+
5943
+ if (normalized.signals) {
5944
+ if (!signals || typeof signals.set !== "function") {
5945
+ throw new Error("Boundary patch includes signals, but no signal registry is available.");
5946
+ }
5947
+ for (const [path, value] of Object.entries(normalized.signals)) {
5948
+ signals.set(path, value);
5949
+ }
5950
+ }
5951
+
5952
+ if (normalized.cache?.browser) {
5953
+ if (!cache || typeof cache.restore !== "function") {
5954
+ throw new Error("Boundary patch includes browser cache, but no cache registry is available.");
5955
+ }
5956
+ cache.restore(normalized.cache.browser);
5957
+ }
5958
+
5959
+ if (normalized.html != null) {
5960
+ loader.swap(normalized.boundary, normalized.html);
5961
+ }
5962
+
5963
+ await flushScheduler(scheduler, normalized.scope);
5964
+
5965
+ if (normalized.redirect) {
5966
+ const result = {
5967
+ status: "redirected",
5968
+ boundary: normalized.boundary,
5969
+ seq: normalized.seq,
5970
+ redirect: normalized.redirect
5971
+ };
5972
+ await followRedirect(normalized.redirect, router, loader);
5973
+ record.applied += 1;
5974
+ record.lastSeq = normalized.seq;
5975
+ record.lastStatus = result.status;
5976
+ remember(result);
5977
+ onApply?.(result, patch);
5978
+ return result;
5979
+ }
5980
+
5981
+ const result = {
5982
+ status: "applied",
5983
+ boundary: normalized.boundary,
5984
+ seq: normalized.seq
5985
+ };
5986
+ record.applied += 1;
5987
+ record.lastSeq = normalized.seq;
5988
+ record.lastStatus = result.status;
5989
+ remember(result);
5990
+ onApply?.(result, patch);
5991
+ return result;
5992
+ }
5993
+
5971
5994
  function boundaryRecord(boundary) {
5972
5995
  if (!boundaries.has(boundary)) {
5973
5996
  boundaries.set(boundary, {
@@ -5975,7 +5998,8 @@
5975
5998
  applied: 0,
5976
5999
  ignored: 0,
5977
6000
  errored: 0,
5978
- lastStatus: undefined
6001
+ lastStatus: undefined,
6002
+ pending: undefined
5979
6003
  });
5980
6004
  }
5981
6005
  return boundaries.get(boundary);