@lynx-js/react 0.123.2 → 0.123.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.
@@ -431,23 +431,36 @@ function createPolyfills() {
431
431
  ]);
432
432
  }
433
433
  };
434
- const ee = new node_events();
435
- ee.dispatchEvent = ({ type, data })=>{
434
+ const createContextProxy = ()=>{
435
+ const ee = new node_events();
436
+ ee.addEventListener = ee.addListener;
437
+ ee.removeEventListener = ee.removeListener;
438
+ return ee;
439
+ };
440
+ const mainThreadContexts = {
441
+ CoreContext: createContextProxy(),
442
+ JsContext: createContextProxy()
443
+ };
444
+ const backgroundThreadContexts = {
445
+ CoreContext: createContextProxy(),
446
+ JsContext: createContextProxy()
447
+ };
448
+ const deliverEvent = (receiver, receiverThread, type, data, origin)=>{
436
449
  if (!globalThis.lynxTestingEnv) return;
437
- const origin = __MAIN_THREAD__ ? 'CoreContext' : 'JSContext';
438
- if ('CoreContext' === origin) lynxTestingEnv.switchToBackgroundThread();
439
- else lynxTestingEnv.switchToMainThread();
440
- ee.emit(type, {
450
+ const wasMainThread = __MAIN_THREAD__;
451
+ if ('main' === receiverThread) lynxTestingEnv.switchToMainThread();
452
+ else lynxTestingEnv.switchToBackgroundThread();
453
+ receiver.emit(type, {
441
454
  data: data,
442
455
  origin
443
456
  });
444
- if ('CoreContext' === origin) lynxTestingEnv.switchToMainThread();
457
+ if (wasMainThread) lynxTestingEnv.switchToMainThread();
445
458
  else lynxTestingEnv.switchToBackgroundThread();
446
459
  };
447
- ee.addEventListener = ee.addListener;
448
- ee.removeEventListener = ee.removeListener;
449
- const CoreContext = ee;
450
- const JsContext = ee;
460
+ mainThreadContexts.CoreContext.dispatchEvent = ({ type, data })=>deliverEvent(mainThreadContexts.CoreContext, 'main', type, data, 'CoreContext');
461
+ mainThreadContexts.JsContext.dispatchEvent = ({ type, data })=>deliverEvent(backgroundThreadContexts.CoreContext, 'background', type, data, 'CoreContext');
462
+ backgroundThreadContexts.CoreContext.dispatchEvent = ({ type, data })=>deliverEvent(mainThreadContexts.JsContext, 'main', type, data, 'JSContext');
463
+ backgroundThreadContexts.JsContext.dispatchEvent = ({ type, data })=>deliverEvent(backgroundThreadContexts.JsContext, 'background', type, data, 'JSContext');
451
464
  function __LoadLepusChunk(chunkName, _options) {
452
465
  const isBackground = !__MAIN_THREAD__;
453
466
  globalThis.lynxTestingEnv.switchToMainThread();
@@ -460,14 +473,14 @@ function createPolyfills() {
460
473
  return {
461
474
  app,
462
475
  performance,
463
- CoreContext,
464
- JsContext,
476
+ mainThreadContexts,
477
+ backgroundThreadContexts,
465
478
  __LoadLepusChunk
466
479
  };
467
480
  }
468
481
  function injectMainThreadGlobals(target, polyfills) {
469
482
  __injectElementApi(target);
470
- const { performance, CoreContext, JsContext, __LoadLepusChunk } = polyfills || {};
483
+ const { performance, mainThreadContexts, __LoadLepusChunk } = polyfills || {};
471
484
  if (void 0 === target) target = globalThis;
472
485
  target.__DEV__ = true;
473
486
  target.__PROFILE__ = true;
@@ -505,8 +518,8 @@ function injectMainThreadGlobals(target, polyfills) {
505
518
  target.lynx = {
506
519
  performance,
507
520
  getNative: ()=>native,
508
- getCoreContext: ()=>CoreContext,
509
- getJSContext: ()=>JsContext,
521
+ getCoreContext: ()=>mainThreadContexts.CoreContext,
522
+ getJSContext: ()=>mainThreadContexts.JsContext,
510
523
  reportError: (e)=>{
511
524
  throw e;
512
525
  }
@@ -550,7 +563,7 @@ class NodesRef {
550
563
  }
551
564
  }
552
565
  function injectBackgroundThreadGlobals(target, polyfills) {
553
- const { app, performance, CoreContext, JsContext, __LoadLepusChunk } = polyfills || {};
566
+ const { app, performance, backgroundThreadContexts, __LoadLepusChunk } = polyfills || {};
554
567
  if (void 0 === target) target = globalThis;
555
568
  target.__DEV__ = true;
556
569
  target.__PROFILE__ = true;
@@ -590,8 +603,8 @@ function injectBackgroundThreadGlobals(target, polyfills) {
590
603
  });
591
604
  }
592
605
  }),
593
- getCoreContext: ()=>CoreContext,
594
- getJSContext: ()=>JsContext,
606
+ getCoreContext: ()=>backgroundThreadContexts.CoreContext,
607
+ getJSContext: ()=>backgroundThreadContexts.JsContext,
595
608
  getJSModule: (moduleName)=>{
596
609
  if ('GlobalEventEmitter' === moduleName) return globalEventEmitter;
597
610
  throw new Error(`getJSModule(${moduleName}) not implemented`);
@@ -6,7 +6,7 @@ import { act } from "preact/test-utils";
6
6
  import { __root } from "@lynx-js/react/internal";
7
7
  import { flushDelayedLifecycleEvents } from "../../runtime/lib/snapshot/lynx/tt.js";
8
8
  import { clearPage } from "../../runtime/lib/snapshot/index.js";
9
- import { __webpack_require__ } from "./0-rslib-runtime.js";
9
+ import { __webpack_require__ } from "./rslib-runtime-0.js";
10
10
  __webpack_require__.add({
11
11
  "../../../node_modules/.pnpm/ansi-regex@5.0.1/node_modules/ansi-regex/index.js" (module1) {
12
12
  module1.exports = ({ onlyFirst = false } = {})=>{
@@ -29,7 +29,7 @@ function withLynxConfig(options) {
29
29
  cwd: options?.rootPath,
30
30
  configPath: options?.configPath
31
31
  });
32
- const { toRstestConfig } = await import("./0-@rstest/adapter-rsbuild.js");
32
+ const { toRstestConfig } = await import("./@rstest/adapter-rsbuild~0.js");
33
33
  const rstestConfig = toRstestConfig({
34
34
  rsbuildConfig: lynxConfig.content
35
35
  });