zova-core 5.1.48 → 5.1.49

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zova-core",
3
- "version": "5.1.48",
4
- "gitHead": "b0e8d884b1c6adc601f6efe1f90c9051cc8a1648",
3
+ "version": "5.1.49",
4
+ "gitHead": "7332ce2a4b44504a88c64da981b60336ebef7e9b",
5
5
  "description": "A vue3 framework with ioc",
6
6
  "keywords": [
7
7
  "ioc",
@@ -51,7 +51,7 @@
51
51
  "@cabloy/vue-compiler-sfc": "^3.5.14",
52
52
  "@cabloy/vue-reactivity": "^3.5.16",
53
53
  "@cabloy/vue-router": "^4.4.16",
54
- "@cabloy/vue-runtime-core": "^3.5.53",
54
+ "@cabloy/vue-runtime-core": "^3.5.56",
55
55
  "@cabloy/vue-runtime-dom": "^3.5.13",
56
56
  "@cabloy/vue-server-renderer": "^3.5.18",
57
57
  "@cabloy/word-utils": "^2.1.14",
@@ -103,7 +103,7 @@ export class BeanContainer {
103
103
  beanInstance,
104
104
  );
105
105
  this.runWithInstanceScopeOrAppContext(() => {
106
- beanInstance.__dispose__();
106
+ return beanInstance.__dispose__();
107
107
  });
108
108
  this.app.meta.module._monkeyModuleSync(
109
109
  false,
@@ -630,8 +630,8 @@ export class BeanContainer {
630
630
  await this.app?.meta.module._monkeyModule(true, 'beanInit', undefined, this, beanInstance);
631
631
  }
632
632
  if (!(beanInstance instanceof BeanAopBase) && beanInstance.__init__) {
633
- await this.runWithInstanceScopeOrAppContext(async () => {
634
- await beanInstance.__init__(...args);
633
+ await this.runWithInstanceScopeOrAppContext(() => {
634
+ return beanInstance.__init__(...args);
635
635
  });
636
636
  }
637
637
  if (this.containerType === 'sys') {
@@ -21,6 +21,7 @@ export class BeanControllerPageBase extends BeanBase {
21
21
 
22
22
  /** @internal */
23
23
  public __updateControllerData() {
24
+ if (!this.app) return;
24
25
  this.app.meta.module._monkeyModuleSync(true, 'controllerDataUpdate', undefined, this);
25
26
  }
26
27
  }
@@ -186,8 +186,8 @@ export class AppModule extends BeanSimple {
186
186
  const mainInstance = this.mainInstances[moduleTarget.info.relativeName];
187
187
  if (mainInstance && mainInstance[monkeyName]) {
188
188
  // @ts-ignore ignore
189
- await this.app.vue.runWithContext(async () => {
190
- await mainInstance[monkeyName](...monkeyData);
189
+ await this.app.vue.runWithContext(() => {
190
+ return mainInstance[monkeyName](...monkeyData);
191
191
  });
192
192
  }
193
193
  }
@@ -197,13 +197,13 @@ export class AppModule extends BeanSimple {
197
197
  if (moduleMonkey.info.capabilities?.monkey) {
198
198
  const monkeyInstance = this.monkeyInstances[key];
199
199
  if (monkeyInstance && monkeyInstance[monkeyName]) {
200
- await this.app.vue.runWithContext(async () => {
200
+ await this.app.vue.runWithContext(() => {
201
201
  if (moduleTarget === undefined) {
202
202
  // @ts-ignore ignore
203
- await monkeyInstance[monkeyName](...monkeyData);
203
+ return monkeyInstance[monkeyName](...monkeyData);
204
204
  } else {
205
205
  // @ts-ignore ignore
206
- await monkeyInstance[monkeyName](moduleTarget, ...monkeyData);
206
+ return monkeyInstance[monkeyName](moduleTarget, ...monkeyData);
207
207
  }
208
208
  });
209
209
  }
@@ -212,13 +212,13 @@ export class AppModule extends BeanSimple {
212
212
  // app monkey
213
213
  const appMonkey = this.app.meta.appMonkey;
214
214
  if (appMonkey && appMonkey[monkeyName]) {
215
- await this.app.vue.runWithContext(async () => {
215
+ await this.app.vue.runWithContext(() => {
216
216
  if (moduleTarget === undefined) {
217
217
  // @ts-ignore ignore
218
- await appMonkey[monkeyName](...monkeyData);
218
+ return appMonkey[monkeyName](...monkeyData);
219
219
  } else {
220
220
  // @ts-ignore ignore
221
- await appMonkey[monkeyName](moduleTarget, ...monkeyData);
221
+ return appMonkey[monkeyName](moduleTarget, ...monkeyData);
222
222
  }
223
223
  });
224
224
  }
@@ -238,8 +238,8 @@ export class AppModule extends BeanSimple {
238
238
  const mainInstance = this.mainInstances[moduleTarget.info.relativeName];
239
239
  if (mainInstance && mainInstance[monkeyName]) {
240
240
  // @ts-ignore ignore
241
- this.app.vue.runWithContext(async () => {
242
- mainInstance[monkeyName](...monkeyData);
241
+ this.app.vue.runWithContext(() => {
242
+ return mainInstance[monkeyName](...monkeyData);
243
243
  });
244
244
  }
245
245
  }
@@ -249,13 +249,13 @@ export class AppModule extends BeanSimple {
249
249
  if (moduleMonkey.info.capabilities?.monkey) {
250
250
  const monkeyInstance = this.monkeyInstances[key];
251
251
  if (monkeyInstance && monkeyInstance[monkeyName]) {
252
- this.app.vue.runWithContext(async () => {
252
+ this.app.vue.runWithContext(() => {
253
253
  if (moduleTarget === undefined) {
254
254
  // @ts-ignore ignore
255
- monkeyInstance[monkeyName](...monkeyData);
255
+ return monkeyInstance[monkeyName](...monkeyData);
256
256
  } else {
257
257
  // @ts-ignore ignore
258
- monkeyInstance[monkeyName](moduleTarget, ...monkeyData);
258
+ return monkeyInstance[monkeyName](moduleTarget, ...monkeyData);
259
259
  }
260
260
  });
261
261
  }
@@ -264,13 +264,13 @@ export class AppModule extends BeanSimple {
264
264
  // app monkey
265
265
  const appMonkey = this.app.meta.appMonkey;
266
266
  if (appMonkey && appMonkey[monkeyName]) {
267
- this.app.vue.runWithContext(async () => {
267
+ this.app.vue.runWithContext(() => {
268
268
  if (moduleTarget === undefined) {
269
269
  // @ts-ignore ignore
270
- appMonkey[monkeyName](...monkeyData);
270
+ return appMonkey[monkeyName](...monkeyData);
271
271
  } else {
272
272
  // @ts-ignore ignore
273
- appMonkey[monkeyName](moduleTarget, ...monkeyData);
273
+ return appMonkey[monkeyName](moduleTarget, ...monkeyData);
274
274
  }
275
275
  });
276
276
  }
@@ -4,15 +4,21 @@ import { BeanSimple } from '../../bean/beanSimple.ts';
4
4
  import { BeanControllerIdentifier, BeanRenderIdentifier } from '../../bean/type.ts';
5
5
  import { cast } from '../../types/utils/cast.ts';
6
6
 
7
+ const SymbolTypeSSRRenderOriginal = Symbol('SymbolTypeSSRRenderOriginal');
8
+ const SymbolTypeSSRRenderResetCount = Symbol('SymbolTypeSSRRenderResetCount');
9
+
7
10
  export class CtxComponent extends BeanSimple {
8
11
  private _bean_render_original: any;
12
+ private _instance_ssrRender_original: any;
13
+ private _renderPatched = false;
14
+ private _ssrRenderReset = false;
9
15
 
10
16
  activate() {
11
17
  if (this.ctx.disposed) return;
12
18
  const renderMethod = 'render';
13
- const self = this;
14
19
  const instance = cast(this.ctx.instance);
15
20
  this._bean_render_original = instance[renderMethod];
21
+ const self = this;
16
22
  instance[renderMethod] = function (this, ...args) {
17
23
  if (instance.isUnmounted) return;
18
24
  if (!self.ctx.meta.state.inited.state) {
@@ -33,16 +39,42 @@ export class CtxComponent extends BeanSimple {
33
39
  // return render.render();
34
40
  // }
35
41
  };
36
- instance.type.ssrRender = null;
42
+ this._renderPatched = true;
43
+ const componentType = cast(instance.type);
44
+ const ssrRenderResetCount = componentType[SymbolTypeSSRRenderResetCount] ?? 0;
45
+ if (ssrRenderResetCount === 0) {
46
+ componentType[SymbolTypeSSRRenderOriginal] = componentType.ssrRender;
47
+ componentType.ssrRender = null;
48
+ }
49
+ componentType[SymbolTypeSSRRenderResetCount] = ssrRenderResetCount + 1;
50
+ this._instance_ssrRender_original = instance.ssrRender;
37
51
  instance.ssrRender = null;
52
+ this._ssrRenderReset = true;
38
53
  }
39
54
 
40
55
  /** @internal */
41
56
  public dispose() {
42
57
  const renderMethod = 'render';
43
58
  const instance = cast(this.ctx.instance);
44
- instance[renderMethod] = this._bean_render_original;
59
+ if (this._renderPatched) {
60
+ instance[renderMethod] = this._bean_render_original;
61
+ }
62
+ if (this._ssrRenderReset) {
63
+ instance.ssrRender = this._instance_ssrRender_original;
64
+ const componentType = cast(instance.type);
65
+ const ssrRenderResetCount = componentType[SymbolTypeSSRRenderResetCount] ?? 0;
66
+ if (ssrRenderResetCount <= 1) {
67
+ componentType.ssrRender = componentType[SymbolTypeSSRRenderOriginal];
68
+ componentType[SymbolTypeSSRRenderOriginal] = undefined;
69
+ componentType[SymbolTypeSSRRenderResetCount] = 0;
70
+ } else {
71
+ componentType[SymbolTypeSSRRenderResetCount] = ssrRenderResetCount - 1;
72
+ }
73
+ }
45
74
  this._bean_render_original = null;
75
+ this._instance_ssrRender_original = null;
76
+ this._renderPatched = false;
77
+ this._ssrRenderReset = false;
46
78
  }
47
79
 
48
80
  private _getRender(): any {
@@ -1,4 +1,4 @@
1
- import { setCurrentInstance } from '@cabloy/vue-runtime-core';
1
+ import { withCurrentInstanceScope, withCurrentInstanceScopeSSR } from '@cabloy/vue-runtime-core';
2
2
  import { pauseTracking, resetTracking } from '@vue/reactivity';
3
3
 
4
4
  import { BeanSimple } from '../../bean/beanSimple.ts';
@@ -9,17 +9,21 @@ export class CtxUtil extends BeanSimple {
9
9
  if (this.ctx.disposed) {
10
10
  throwErrorComponentUnmounted();
11
11
  }
12
- const reset = setCurrentInstance(this.ctx.instance as any);
13
- if (!tracking) {
14
- pauseTracking();
15
- }
16
- try {
17
- return fn();
18
- } finally {
12
+ const instance = this.ctx.instance as any;
13
+ const runner = process.env.SERVER ? withCurrentInstanceScopeSSR : withCurrentInstanceScope;
14
+ const result = runner(instance, () => {
19
15
  if (!tracking) {
20
- resetTracking();
16
+ pauseTracking();
21
17
  }
22
- reset();
23
- }
18
+ try {
19
+ const result = fn();
20
+ return result;
21
+ } finally {
22
+ if (!tracking) {
23
+ resetTracking();
24
+ }
25
+ }
26
+ });
27
+ return result;
24
28
  }
25
29
  }