@shuvi/platform-shared 2.0.0-dev.35 → 2.0.0-dev.37

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.
@@ -12,6 +12,29 @@ import { initPlugins } from './runtimPlugin';
12
12
  import { doura } from 'doura';
13
13
  import { errorModel, errorModelName } from './models/error';
14
14
  import { loaderModel, loaderModelName } from './models/loader';
15
+ // MessageChannel is not clamped like nested setTimeout; scheduler.yield is used where available.
16
+ const yieldToMain = () => {
17
+ if (typeof window === 'undefined' ||
18
+ !process.env.__SHUVI__HYDRATE_IN_TRANSITION__) {
19
+ return Promise.resolve();
20
+ }
21
+ const scheduler = globalThis.scheduler;
22
+ if (scheduler === null || scheduler === void 0 ? void 0 : scheduler.yield) {
23
+ return scheduler.yield();
24
+ }
25
+ return new Promise(resolve => {
26
+ if (typeof MessageChannel === 'undefined') {
27
+ setTimeout(resolve, 0);
28
+ return;
29
+ }
30
+ const channel = new MessageChannel();
31
+ channel.port1.onmessage = () => {
32
+ channel.port1.close();
33
+ resolve();
34
+ };
35
+ channel.port2.postMessage(null);
36
+ });
37
+ };
15
38
  export class ApplicationImpl {
16
39
  constructor(options) {
17
40
  this._config = options.config;
@@ -62,6 +85,7 @@ export class ApplicationImpl {
62
85
  init() {
63
86
  return __awaiter(this, void 0, void 0, function* () {
64
87
  yield this._initPlugin();
88
+ yield yieldToMain();
65
89
  yield this._initAppContext();
66
90
  this._router.init();
67
91
  yield this._initAppComponent();
@@ -15,6 +15,29 @@ const runtimPlugin_2 = require("./runtimPlugin");
15
15
  const doura_1 = require("doura");
16
16
  const error_1 = require("./models/error");
17
17
  const loader_1 = require("./models/loader");
18
+ // MessageChannel is not clamped like nested setTimeout; scheduler.yield is used where available.
19
+ const yieldToMain = () => {
20
+ if (typeof window === 'undefined' ||
21
+ !process.env.__SHUVI__HYDRATE_IN_TRANSITION__) {
22
+ return Promise.resolve();
23
+ }
24
+ const scheduler = globalThis.scheduler;
25
+ if (scheduler === null || scheduler === void 0 ? void 0 : scheduler.yield) {
26
+ return scheduler.yield();
27
+ }
28
+ return new Promise(resolve => {
29
+ if (typeof MessageChannel === 'undefined') {
30
+ setTimeout(resolve, 0);
31
+ return;
32
+ }
33
+ const channel = new MessageChannel();
34
+ channel.port1.onmessage = () => {
35
+ channel.port1.close();
36
+ resolve();
37
+ };
38
+ channel.port2.postMessage(null);
39
+ });
40
+ };
18
41
  class ApplicationImpl {
19
42
  constructor(options) {
20
43
  this._config = options.config;
@@ -65,6 +88,7 @@ class ApplicationImpl {
65
88
  init() {
66
89
  return __awaiter(this, void 0, void 0, function* () {
67
90
  yield this._initPlugin();
91
+ yield yieldToMain();
68
92
  yield this._initAppContext();
69
93
  this._router.init();
70
94
  yield this._initAppComponent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/platform-shared",
3
- "version": "2.0.0-dev.35",
3
+ "version": "2.0.0-dev.37",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -83,19 +83,19 @@
83
83
  "node": ">= 16.0.0"
84
84
  },
85
85
  "dependencies": {
86
- "@shuvi/hook": "2.0.0-dev.35",
86
+ "@shuvi/hook": "2.0.0-dev.37",
87
87
  "doura": "0.0.13",
88
- "@shuvi/router": "2.0.0-dev.35",
89
- "@shuvi/runtime": "2.0.0-dev.35",
90
- "@shuvi/shared": "2.0.0-dev.35",
91
- "@shuvi/toolpack": "2.0.0-dev.35",
92
- "@shuvi/utils": "2.0.0-dev.35"
88
+ "@shuvi/router": "2.0.0-dev.37",
89
+ "@shuvi/runtime": "2.0.0-dev.37",
90
+ "@shuvi/shared": "2.0.0-dev.37",
91
+ "@shuvi/toolpack": "2.0.0-dev.37",
92
+ "@shuvi/utils": "2.0.0-dev.37"
93
93
  },
94
94
  "peerDependencies": {
95
- "@shuvi/service": "2.0.0-dev.35"
95
+ "@shuvi/service": "2.0.0-dev.37"
96
96
  },
97
97
  "devDependencies": {
98
- "@shuvi/service": "2.0.0-dev.35",
98
+ "@shuvi/service": "2.0.0-dev.37",
99
99
  "@types/minimatch": "3.0.5"
100
100
  }
101
101
  }