@lvce-editor/extension-management-worker 4.83.2 → 4.83.3

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.
@@ -4898,11 +4898,12 @@ const hasView = (extension, viewId) => {
4898
4898
  const hasOnlyViewAndCommandActivations = extension => {
4899
4899
  return Array.isArray(extension.activation) && extension.activation.length > 0 && extension.activation.every(event => event.startsWith('onView:') || event.startsWith('onCommand:'));
4900
4900
  };
4901
+ const pendingViewCreations = new WeakMap();
4901
4902
  const hasOtherViewInstances = rpc => {
4902
4903
  return getEntries().some(entry => entry.instance.status === 'ready' && entry.instance.rpc === rpc);
4903
4904
  };
4904
4905
  const disposeViewOnlyExtensionWorker = async (extensionId, rpc) => {
4905
- if (hasOtherViewInstances(rpc)) {
4906
+ if (pendingViewCreations.has(rpc) || hasOtherViewInstances(rpc)) {
4906
4907
  return;
4907
4908
  }
4908
4909
  if (get$2(extensionId) !== rpc) {
@@ -4918,7 +4919,7 @@ const getExtensionForView = async (viewId, assetDir, platform, applicationId) =>
4918
4919
  }
4919
4920
  return extension;
4920
4921
  };
4921
- const getRpcForView = async (viewId, assetDir, platform, applicationId) => {
4922
+ const getRpcForView = async (viewId, assetDir, platform, applicationId, retain) => {
4922
4923
  const {
4923
4924
  assetDir: resolvedAssetDir,
4924
4925
  platform: resolvedPlatform
@@ -4928,22 +4929,26 @@ const getRpcForView = async (viewId, assetDir, platform, applicationId) => {
4928
4929
  const existingRpc = get$2(extensionId, applicationId);
4929
4930
  // Application teardown and reload own application workers; global view-only disposal does not.
4930
4931
  if (existingRpc) {
4931
- return {
4932
+ const worker = {
4932
4933
  disposeWorkerWhenLastViewCloses: applicationId === undefined && hasOnlyViewAndCommandActivations(extension),
4933
4934
  extensionId,
4934
4935
  rpc: existingRpc
4935
4936
  };
4937
+ retain?.(worker);
4938
+ return worker;
4936
4939
  }
4937
4940
  const activationResult = await activateByEvent(`onView:${viewId}`, resolvedAssetDir, resolvedPlatform, get$7(applicationId));
4938
4941
  if (activationResult.error) {
4939
4942
  throw activationResult.error;
4940
4943
  }
4941
4944
  const rpc = await getRpc$1(extension, resolvedAssetDir, resolvedPlatform);
4942
- return {
4945
+ const worker = {
4943
4946
  disposeWorkerWhenLastViewCloses: applicationId === undefined && hasOnlyViewAndCommandActivations(extension),
4944
4947
  extensionId,
4945
4948
  rpc
4946
4949
  };
4950
+ retain?.(worker);
4951
+ return worker;
4947
4952
  };
4948
4953
  const getRpcForInstance = async (viewId, uid, assetDir, platform) => {
4949
4954
  const instance = get$1(uid);
@@ -4972,12 +4977,18 @@ const getViewMetadata = async (rpc, viewId) => {
4972
4977
  };
4973
4978
  };
4974
4979
  const createViewInstance = async (viewId, uid, context, assetDir, platform, applicationId) => {
4980
+ let retainedWorker;
4981
+ const retain = worker => {
4982
+ retainedWorker = worker;
4983
+ pendingViewCreations.set(worker.rpc, (pendingViewCreations.get(worker.rpc) || 0) + 1);
4984
+ };
4975
4985
  try {
4986
+ // Retain at selection time, before yielding the RPC to the caller.
4976
4987
  const {
4977
4988
  disposeWorkerWhenLastViewCloses,
4978
4989
  extensionId,
4979
4990
  rpc
4980
- } = await getRpcForView(viewId, assetDir, platform, applicationId);
4991
+ } = await getRpcForView(viewId, assetDir, platform, applicationId, retain);
4981
4992
  const {
4982
4993
  eventListeners,
4983
4994
  stateful
@@ -5015,6 +5026,24 @@ const createViewInstance = async (viewId, uid, context, assetDir, platform, appl
5015
5026
  error: serializedError,
5016
5027
  ok: false
5017
5028
  };
5029
+ } finally {
5030
+ if (retainedWorker) {
5031
+ const {
5032
+ disposeWorkerWhenLastViewCloses,
5033
+ extensionId,
5034
+ rpc
5035
+ } = retainedWorker;
5036
+ const remaining = (pendingViewCreations.get(rpc) || 1) - 1;
5037
+ if (remaining) {
5038
+ pendingViewCreations.set(rpc, remaining);
5039
+ } else {
5040
+ pendingViewCreations.delete(rpc);
5041
+ }
5042
+ // Failed creations must also release a worker kept alive by an overlapping close.
5043
+ if (disposeWorkerWhenLastViewCloses) {
5044
+ await disposeViewOnlyExtensionWorker(extensionId, rpc);
5045
+ }
5046
+ }
5018
5047
  }
5019
5048
  };
5020
5049
  const dispatchViewEvent = async (viewId, uid, event, assetDir, platform) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "4.83.2",
3
+ "version": "4.83.3",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"