hadars 0.1.24 → 0.1.26
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/dist/cli.js +93 -62
- package/dist/index.js +0 -2
- package/dist/slim-react/index.cjs +91 -41
- package/dist/slim-react/index.js +91 -44
- package/dist/slim-react/jsx-runtime.js +0 -1
- package/dist/ssr-render-worker.js +81 -46
- package/dist/ssr-watch.js +12 -17
- package/package.json +1 -1
- package/src/slim-react/render.ts +50 -16
- package/src/slim-react/renderContext.ts +34 -38
- package/src/utils/rspack.ts +9 -13
- package/dist/chunk-EZUCZHGV.js +0 -11
package/dist/slim-react/index.js
CHANGED
|
@@ -7,44 +7,36 @@ import {
|
|
|
7
7
|
createElement,
|
|
8
8
|
jsx
|
|
9
9
|
} from "../chunk-OS3V4CPN.js";
|
|
10
|
-
import {
|
|
11
|
-
__require
|
|
12
|
-
} from "../chunk-EZUCZHGV.js";
|
|
13
10
|
|
|
14
11
|
// src/slim-react/renderContext.ts
|
|
15
|
-
var
|
|
12
|
+
var MAP_KEY = "__slimReactContextMap";
|
|
16
13
|
var _g = globalThis;
|
|
17
|
-
if (!_g
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
14
|
+
if (!("__slimReactContextMap" in _g))
|
|
15
|
+
_g[MAP_KEY] = null;
|
|
16
|
+
function swapContextMap(map) {
|
|
17
|
+
const prev = _g[MAP_KEY];
|
|
18
|
+
_g[MAP_KEY] = map;
|
|
19
|
+
return prev;
|
|
24
20
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return _contextStore ? _contextStore.run(/* @__PURE__ */ new Map(), fn) : fn();
|
|
21
|
+
function captureMap() {
|
|
22
|
+
return _g[MAP_KEY];
|
|
28
23
|
}
|
|
29
24
|
function getContextValue(context) {
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
return
|
|
25
|
+
const map = _g[MAP_KEY];
|
|
26
|
+
if (map && map.has(context))
|
|
27
|
+
return map.get(context);
|
|
33
28
|
const c = context;
|
|
34
29
|
return "_defaultValue" in c ? c._defaultValue : c._currentValue;
|
|
35
30
|
}
|
|
36
31
|
function pushContextValue(context, value) {
|
|
37
|
-
const
|
|
32
|
+
const map = _g[MAP_KEY];
|
|
38
33
|
const c = context;
|
|
39
|
-
const prev =
|
|
40
|
-
|
|
41
|
-
store.set(context, value);
|
|
34
|
+
const prev = map && map.has(context) ? map.get(context) : "_defaultValue" in c ? c._defaultValue : c._currentValue;
|
|
35
|
+
map?.set(context, value);
|
|
42
36
|
return prev;
|
|
43
37
|
}
|
|
44
38
|
function popContextValue(context, prev) {
|
|
45
|
-
|
|
46
|
-
if (store)
|
|
47
|
-
store.set(context, prev);
|
|
39
|
+
_g[MAP_KEY]?.set(context, prev);
|
|
48
40
|
}
|
|
49
41
|
var GLOBAL_KEY = "__slimReactRenderState";
|
|
50
42
|
var EMPTY = { id: 0, overflow: "", bits: 0 };
|
|
@@ -590,10 +582,18 @@ function renderComponent(type, props, writer, isSvg) {
|
|
|
590
582
|
};
|
|
591
583
|
const r2 = renderChildren(props.children, writer, isSvg);
|
|
592
584
|
if (r2 && typeof r2.then === "function") {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
585
|
+
const m = captureMap();
|
|
586
|
+
return r2.then(
|
|
587
|
+
() => {
|
|
588
|
+
swapContextMap(m);
|
|
589
|
+
finish2();
|
|
590
|
+
},
|
|
591
|
+
(e) => {
|
|
592
|
+
swapContextMap(m);
|
|
593
|
+
finish2();
|
|
594
|
+
throw e;
|
|
595
|
+
}
|
|
596
|
+
);
|
|
597
597
|
}
|
|
598
598
|
finish2();
|
|
599
599
|
return;
|
|
@@ -623,26 +623,45 @@ function renderComponent(type, props, writer, isSvg) {
|
|
|
623
623
|
popContextValue(ctx, prevCtxValue);
|
|
624
624
|
};
|
|
625
625
|
if (result instanceof Promise) {
|
|
626
|
+
const m = captureMap();
|
|
626
627
|
return result.then((resolved) => {
|
|
628
|
+
swapContextMap(m);
|
|
627
629
|
const r2 = renderNode(resolved, writer, isSvg);
|
|
628
630
|
if (r2 && typeof r2.then === "function") {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
631
|
+
const m2 = captureMap();
|
|
632
|
+
return r2.then(
|
|
633
|
+
() => {
|
|
634
|
+
swapContextMap(m2);
|
|
635
|
+
finish();
|
|
636
|
+
},
|
|
637
|
+
(e) => {
|
|
638
|
+
swapContextMap(m2);
|
|
639
|
+
finish();
|
|
640
|
+
throw e;
|
|
641
|
+
}
|
|
642
|
+
);
|
|
633
643
|
}
|
|
634
644
|
finish();
|
|
635
645
|
}, (e) => {
|
|
646
|
+
swapContextMap(m);
|
|
636
647
|
finish();
|
|
637
648
|
throw e;
|
|
638
649
|
});
|
|
639
650
|
}
|
|
640
651
|
const r = renderNode(result, writer, isSvg);
|
|
641
652
|
if (r && typeof r.then === "function") {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
653
|
+
const m = captureMap();
|
|
654
|
+
return r.then(
|
|
655
|
+
() => {
|
|
656
|
+
swapContextMap(m);
|
|
657
|
+
finish();
|
|
658
|
+
},
|
|
659
|
+
(e) => {
|
|
660
|
+
swapContextMap(m);
|
|
661
|
+
finish();
|
|
662
|
+
throw e;
|
|
663
|
+
}
|
|
664
|
+
);
|
|
646
665
|
}
|
|
647
666
|
finish();
|
|
648
667
|
}
|
|
@@ -658,7 +677,9 @@ function renderChildArray(children, writer, isSvg) {
|
|
|
658
677
|
const savedTree = pushTreeContext(totalChildren, i);
|
|
659
678
|
const r = renderNode(children[i], writer, isSvg);
|
|
660
679
|
if (r && typeof r.then === "function") {
|
|
680
|
+
const m = captureMap();
|
|
661
681
|
return r.then(() => {
|
|
682
|
+
swapContextMap(m);
|
|
662
683
|
popTreeContext(savedTree);
|
|
663
684
|
return renderChildArrayFrom(children, i + 1, writer, isSvg);
|
|
664
685
|
});
|
|
@@ -675,7 +696,9 @@ function renderChildArrayFrom(children, startIndex, writer, isSvg) {
|
|
|
675
696
|
const savedTree = pushTreeContext(totalChildren, i);
|
|
676
697
|
const r = renderNode(children[i], writer, isSvg);
|
|
677
698
|
if (r && typeof r.then === "function") {
|
|
699
|
+
const m = captureMap();
|
|
678
700
|
return r.then(() => {
|
|
701
|
+
swapContextMap(m);
|
|
679
702
|
popTreeContext(savedTree);
|
|
680
703
|
return renderChildArrayFrom(children, i + 1, writer, isSvg);
|
|
681
704
|
});
|
|
@@ -702,7 +725,9 @@ async function renderSuspense(props, writer, isSvg = false) {
|
|
|
702
725
|
const buffer = new BufferWriter();
|
|
703
726
|
const r = renderNode(children, buffer, isSvg);
|
|
704
727
|
if (r && typeof r.then === "function") {
|
|
728
|
+
const m = captureMap();
|
|
705
729
|
await r;
|
|
730
|
+
swapContextMap(m);
|
|
706
731
|
}
|
|
707
732
|
writer.write("<!--$-->");
|
|
708
733
|
buffer.flush(writer);
|
|
@@ -710,7 +735,9 @@ async function renderSuspense(props, writer, isSvg = false) {
|
|
|
710
735
|
return;
|
|
711
736
|
} catch (error) {
|
|
712
737
|
if (error && typeof error.then === "function") {
|
|
738
|
+
const m = captureMap();
|
|
713
739
|
await error;
|
|
740
|
+
swapContextMap(m);
|
|
714
741
|
attempts++;
|
|
715
742
|
} else {
|
|
716
743
|
throw error;
|
|
@@ -721,16 +748,21 @@ async function renderSuspense(props, writer, isSvg = false) {
|
|
|
721
748
|
writer.write("<!--$?-->");
|
|
722
749
|
if (fallback) {
|
|
723
750
|
const r = renderNode(fallback, writer, isSvg);
|
|
724
|
-
if (r && typeof r.then === "function")
|
|
751
|
+
if (r && typeof r.then === "function") {
|
|
752
|
+
const m = captureMap();
|
|
725
753
|
await r;
|
|
754
|
+
swapContextMap(m);
|
|
755
|
+
}
|
|
726
756
|
}
|
|
727
757
|
writer.write("<!--/$-->");
|
|
728
758
|
}
|
|
729
759
|
function renderToStream(element) {
|
|
730
760
|
const encoder = new TextEncoder();
|
|
731
|
-
|
|
761
|
+
const contextMap = /* @__PURE__ */ new Map();
|
|
762
|
+
return new ReadableStream({
|
|
732
763
|
async start(controller) {
|
|
733
764
|
resetRenderState();
|
|
765
|
+
const prev = swapContextMap(contextMap);
|
|
734
766
|
const writer = {
|
|
735
767
|
lastWasText: false,
|
|
736
768
|
write(chunk) {
|
|
@@ -744,19 +776,27 @@ function renderToStream(element) {
|
|
|
744
776
|
};
|
|
745
777
|
try {
|
|
746
778
|
const r = renderNode(element, writer);
|
|
747
|
-
if (r && typeof r.then === "function")
|
|
779
|
+
if (r && typeof r.then === "function") {
|
|
780
|
+
const m = captureMap();
|
|
748
781
|
await r;
|
|
782
|
+
swapContextMap(m);
|
|
783
|
+
}
|
|
749
784
|
controller.close();
|
|
750
785
|
} catch (error) {
|
|
751
786
|
controller.error(error);
|
|
787
|
+
} finally {
|
|
788
|
+
swapContextMap(prev);
|
|
752
789
|
}
|
|
753
790
|
}
|
|
754
|
-
})
|
|
791
|
+
});
|
|
755
792
|
}
|
|
756
|
-
function renderToString(element) {
|
|
757
|
-
|
|
793
|
+
async function renderToString(element) {
|
|
794
|
+
const contextMap = /* @__PURE__ */ new Map();
|
|
795
|
+
const prev = swapContextMap(contextMap);
|
|
796
|
+
try {
|
|
758
797
|
for (let attempt = 0; attempt < MAX_SUSPENSE_RETRIES; attempt++) {
|
|
759
798
|
resetRenderState();
|
|
799
|
+
swapContextMap(contextMap);
|
|
760
800
|
const chunks = [];
|
|
761
801
|
const writer = {
|
|
762
802
|
lastWasText: false,
|
|
@@ -771,19 +811,26 @@ function renderToString(element) {
|
|
|
771
811
|
};
|
|
772
812
|
try {
|
|
773
813
|
const r = renderNode(element, writer);
|
|
774
|
-
if (r && typeof r.then === "function")
|
|
814
|
+
if (r && typeof r.then === "function") {
|
|
815
|
+
const m = captureMap();
|
|
775
816
|
await r;
|
|
817
|
+
swapContextMap(m);
|
|
818
|
+
}
|
|
776
819
|
return chunks.join("");
|
|
777
820
|
} catch (error) {
|
|
778
821
|
if (error && typeof error.then === "function") {
|
|
822
|
+
const m = captureMap();
|
|
779
823
|
await error;
|
|
824
|
+
swapContextMap(m);
|
|
780
825
|
continue;
|
|
781
826
|
}
|
|
782
827
|
throw error;
|
|
783
828
|
}
|
|
784
829
|
}
|
|
785
830
|
throw new Error("[slim-react] renderToString exceeded maximum retries");
|
|
786
|
-
}
|
|
831
|
+
} finally {
|
|
832
|
+
swapContextMap(prev);
|
|
833
|
+
}
|
|
787
834
|
}
|
|
788
835
|
|
|
789
836
|
// src/slim-react/index.ts
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
1
|
// src/ssr-render-worker.ts
|
|
10
2
|
import { workerData, parentPort } from "node:worker_threads";
|
|
11
3
|
import { pathToFileURL } from "node:url";
|
|
@@ -75,39 +67,34 @@ function createElement(type, props, ...children) {
|
|
|
75
67
|
}
|
|
76
68
|
|
|
77
69
|
// src/slim-react/renderContext.ts
|
|
78
|
-
var
|
|
70
|
+
var MAP_KEY = "__slimReactContextMap";
|
|
79
71
|
var _g = globalThis;
|
|
80
|
-
if (!_g
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
72
|
+
if (!("__slimReactContextMap" in _g))
|
|
73
|
+
_g[MAP_KEY] = null;
|
|
74
|
+
function swapContextMap(map) {
|
|
75
|
+
const prev = _g[MAP_KEY];
|
|
76
|
+
_g[MAP_KEY] = map;
|
|
77
|
+
return prev;
|
|
87
78
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return _contextStore ? _contextStore.run(/* @__PURE__ */ new Map(), fn) : fn();
|
|
79
|
+
function captureMap() {
|
|
80
|
+
return _g[MAP_KEY];
|
|
91
81
|
}
|
|
92
82
|
function getContextValue(context) {
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
return
|
|
83
|
+
const map = _g[MAP_KEY];
|
|
84
|
+
if (map && map.has(context))
|
|
85
|
+
return map.get(context);
|
|
96
86
|
const c = context;
|
|
97
87
|
return "_defaultValue" in c ? c._defaultValue : c._currentValue;
|
|
98
88
|
}
|
|
99
89
|
function pushContextValue(context, value) {
|
|
100
|
-
const
|
|
90
|
+
const map = _g[MAP_KEY];
|
|
101
91
|
const c = context;
|
|
102
|
-
const prev =
|
|
103
|
-
|
|
104
|
-
store.set(context, value);
|
|
92
|
+
const prev = map && map.has(context) ? map.get(context) : "_defaultValue" in c ? c._defaultValue : c._currentValue;
|
|
93
|
+
map?.set(context, value);
|
|
105
94
|
return prev;
|
|
106
95
|
}
|
|
107
96
|
function popContextValue(context, prev) {
|
|
108
|
-
|
|
109
|
-
if (store)
|
|
110
|
-
store.set(context, prev);
|
|
97
|
+
_g[MAP_KEY]?.set(context, prev);
|
|
111
98
|
}
|
|
112
99
|
var GLOBAL_KEY = "__slimReactRenderState";
|
|
113
100
|
var EMPTY = { id: 0, overflow: "", bits: 0 };
|
|
@@ -547,10 +534,18 @@ function renderComponent(type, props, writer, isSvg) {
|
|
|
547
534
|
};
|
|
548
535
|
const r2 = renderChildren(props.children, writer, isSvg);
|
|
549
536
|
if (r2 && typeof r2.then === "function") {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
537
|
+
const m = captureMap();
|
|
538
|
+
return r2.then(
|
|
539
|
+
() => {
|
|
540
|
+
swapContextMap(m);
|
|
541
|
+
finish2();
|
|
542
|
+
},
|
|
543
|
+
(e) => {
|
|
544
|
+
swapContextMap(m);
|
|
545
|
+
finish2();
|
|
546
|
+
throw e;
|
|
547
|
+
}
|
|
548
|
+
);
|
|
554
549
|
}
|
|
555
550
|
finish2();
|
|
556
551
|
return;
|
|
@@ -580,26 +575,45 @@ function renderComponent(type, props, writer, isSvg) {
|
|
|
580
575
|
popContextValue(ctx, prevCtxValue);
|
|
581
576
|
};
|
|
582
577
|
if (result instanceof Promise) {
|
|
578
|
+
const m = captureMap();
|
|
583
579
|
return result.then((resolved) => {
|
|
580
|
+
swapContextMap(m);
|
|
584
581
|
const r2 = renderNode(resolved, writer, isSvg);
|
|
585
582
|
if (r2 && typeof r2.then === "function") {
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
583
|
+
const m2 = captureMap();
|
|
584
|
+
return r2.then(
|
|
585
|
+
() => {
|
|
586
|
+
swapContextMap(m2);
|
|
587
|
+
finish();
|
|
588
|
+
},
|
|
589
|
+
(e) => {
|
|
590
|
+
swapContextMap(m2);
|
|
591
|
+
finish();
|
|
592
|
+
throw e;
|
|
593
|
+
}
|
|
594
|
+
);
|
|
590
595
|
}
|
|
591
596
|
finish();
|
|
592
597
|
}, (e) => {
|
|
598
|
+
swapContextMap(m);
|
|
593
599
|
finish();
|
|
594
600
|
throw e;
|
|
595
601
|
});
|
|
596
602
|
}
|
|
597
603
|
const r = renderNode(result, writer, isSvg);
|
|
598
604
|
if (r && typeof r.then === "function") {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
605
|
+
const m = captureMap();
|
|
606
|
+
return r.then(
|
|
607
|
+
() => {
|
|
608
|
+
swapContextMap(m);
|
|
609
|
+
finish();
|
|
610
|
+
},
|
|
611
|
+
(e) => {
|
|
612
|
+
swapContextMap(m);
|
|
613
|
+
finish();
|
|
614
|
+
throw e;
|
|
615
|
+
}
|
|
616
|
+
);
|
|
603
617
|
}
|
|
604
618
|
finish();
|
|
605
619
|
}
|
|
@@ -615,7 +629,9 @@ function renderChildArray(children, writer, isSvg) {
|
|
|
615
629
|
const savedTree = pushTreeContext(totalChildren, i);
|
|
616
630
|
const r = renderNode(children[i], writer, isSvg);
|
|
617
631
|
if (r && typeof r.then === "function") {
|
|
632
|
+
const m = captureMap();
|
|
618
633
|
return r.then(() => {
|
|
634
|
+
swapContextMap(m);
|
|
619
635
|
popTreeContext(savedTree);
|
|
620
636
|
return renderChildArrayFrom(children, i + 1, writer, isSvg);
|
|
621
637
|
});
|
|
@@ -632,7 +648,9 @@ function renderChildArrayFrom(children, startIndex, writer, isSvg) {
|
|
|
632
648
|
const savedTree = pushTreeContext(totalChildren, i);
|
|
633
649
|
const r = renderNode(children[i], writer, isSvg);
|
|
634
650
|
if (r && typeof r.then === "function") {
|
|
651
|
+
const m = captureMap();
|
|
635
652
|
return r.then(() => {
|
|
653
|
+
swapContextMap(m);
|
|
636
654
|
popTreeContext(savedTree);
|
|
637
655
|
return renderChildArrayFrom(children, i + 1, writer, isSvg);
|
|
638
656
|
});
|
|
@@ -659,7 +677,9 @@ async function renderSuspense(props, writer, isSvg = false) {
|
|
|
659
677
|
const buffer = new BufferWriter();
|
|
660
678
|
const r = renderNode(children, buffer, isSvg);
|
|
661
679
|
if (r && typeof r.then === "function") {
|
|
680
|
+
const m = captureMap();
|
|
662
681
|
await r;
|
|
682
|
+
swapContextMap(m);
|
|
663
683
|
}
|
|
664
684
|
writer.write("<!--$-->");
|
|
665
685
|
buffer.flush(writer);
|
|
@@ -667,7 +687,9 @@ async function renderSuspense(props, writer, isSvg = false) {
|
|
|
667
687
|
return;
|
|
668
688
|
} catch (error) {
|
|
669
689
|
if (error && typeof error.then === "function") {
|
|
690
|
+
const m = captureMap();
|
|
670
691
|
await error;
|
|
692
|
+
swapContextMap(m);
|
|
671
693
|
attempts++;
|
|
672
694
|
} else {
|
|
673
695
|
throw error;
|
|
@@ -678,15 +700,21 @@ async function renderSuspense(props, writer, isSvg = false) {
|
|
|
678
700
|
writer.write("<!--$?-->");
|
|
679
701
|
if (fallback) {
|
|
680
702
|
const r = renderNode(fallback, writer, isSvg);
|
|
681
|
-
if (r && typeof r.then === "function")
|
|
703
|
+
if (r && typeof r.then === "function") {
|
|
704
|
+
const m = captureMap();
|
|
682
705
|
await r;
|
|
706
|
+
swapContextMap(m);
|
|
707
|
+
}
|
|
683
708
|
}
|
|
684
709
|
writer.write("<!--/$-->");
|
|
685
710
|
}
|
|
686
|
-
function renderToString(element) {
|
|
687
|
-
|
|
711
|
+
async function renderToString(element) {
|
|
712
|
+
const contextMap = /* @__PURE__ */ new Map();
|
|
713
|
+
const prev = swapContextMap(contextMap);
|
|
714
|
+
try {
|
|
688
715
|
for (let attempt = 0; attempt < MAX_SUSPENSE_RETRIES; attempt++) {
|
|
689
716
|
resetRenderState();
|
|
717
|
+
swapContextMap(contextMap);
|
|
690
718
|
const chunks = [];
|
|
691
719
|
const writer = {
|
|
692
720
|
lastWasText: false,
|
|
@@ -701,19 +729,26 @@ function renderToString(element) {
|
|
|
701
729
|
};
|
|
702
730
|
try {
|
|
703
731
|
const r = renderNode(element, writer);
|
|
704
|
-
if (r && typeof r.then === "function")
|
|
732
|
+
if (r && typeof r.then === "function") {
|
|
733
|
+
const m = captureMap();
|
|
705
734
|
await r;
|
|
735
|
+
swapContextMap(m);
|
|
736
|
+
}
|
|
706
737
|
return chunks.join("");
|
|
707
738
|
} catch (error) {
|
|
708
739
|
if (error && typeof error.then === "function") {
|
|
740
|
+
const m = captureMap();
|
|
709
741
|
await error;
|
|
742
|
+
swapContextMap(m);
|
|
710
743
|
continue;
|
|
711
744
|
}
|
|
712
745
|
throw error;
|
|
713
746
|
}
|
|
714
747
|
}
|
|
715
748
|
throw new Error("[slim-react] renderToString exceeded maximum retries");
|
|
716
|
-
}
|
|
749
|
+
} finally {
|
|
750
|
+
swapContextMap(prev);
|
|
751
|
+
}
|
|
717
752
|
}
|
|
718
753
|
|
|
719
754
|
// src/ssr-render-worker.ts
|
package/dist/ssr-watch.js
CHANGED
|
@@ -171,30 +171,22 @@ var buildCompilerConfig = (entry2, opts, includeHotPlugin) => {
|
|
|
171
171
|
// Route all React imports to slim-react for SSR.
|
|
172
172
|
react: slimReactIndex,
|
|
173
173
|
"react/jsx-runtime": slimReactJsx,
|
|
174
|
-
"react/jsx-dev-runtime": slimReactJsx
|
|
175
|
-
//
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
"@emotion/styled": path.resolve(process.cwd(), "node_modules", "@emotion", "styled")
|
|
174
|
+
"react/jsx-dev-runtime": slimReactJsx
|
|
175
|
+
// @emotion/* is bundled (not external) so that its `react` imports are
|
|
176
|
+
// resolved through the alias above to slim-react. If left external,
|
|
177
|
+
// emotion loads real React from node_modules and calls
|
|
178
|
+
// ReactSharedInternals.H.useContext which requires React's dispatcher.
|
|
180
179
|
} : void 0;
|
|
181
180
|
const externals = isServerBuild ? [
|
|
182
181
|
// Node.js built-ins — must not be bundled; resolved by the runtime.
|
|
183
|
-
// Both the bare name and the node: prefix are listed because rspack
|
|
184
|
-
// may encounter either form depending on how the import is written.
|
|
185
|
-
"node:async_hooks",
|
|
186
|
-
"async_hooks",
|
|
187
182
|
"node:fs",
|
|
188
183
|
"node:path",
|
|
189
184
|
"node:os",
|
|
190
185
|
"node:stream",
|
|
191
186
|
"node:util",
|
|
192
|
-
//
|
|
193
|
-
//
|
|
194
|
-
"@emotion/
|
|
195
|
-
"@emotion/server",
|
|
196
|
-
"@emotion/cache",
|
|
197
|
-
"@emotion/styled"
|
|
187
|
+
// @emotion/server is only used outside component rendering (CSS extraction)
|
|
188
|
+
// and does not call React hooks, so it is safe to leave as external.
|
|
189
|
+
"@emotion/server"
|
|
198
190
|
] : void 0;
|
|
199
191
|
const extraPlugins = [];
|
|
200
192
|
if (opts.define && typeof opts.define === "object") {
|
|
@@ -209,7 +201,10 @@ var buildCompilerConfig = (entry2, opts, includeHotPlugin) => {
|
|
|
209
201
|
extensions: [".tsx", ".ts", ".js", ".jsx"],
|
|
210
202
|
alias: resolveAliases,
|
|
211
203
|
// for server builds prefer the package "main"/"module" fields and avoid "browser" so we don't pick browser-specific entrypoints
|
|
212
|
-
mainFields: isServerBuild ? ["main", "module"] : ["browser", "module", "main"]
|
|
204
|
+
mainFields: isServerBuild ? ["main", "module"] : ["browser", "module", "main"],
|
|
205
|
+
// for server builds exclude the "browser" condition so packages with package.json
|
|
206
|
+
// "exports" conditions (e.g. @emotion/*) resolve their Node/CJS entry, not the browser build
|
|
207
|
+
...isServerBuild ? { conditionNames: ["node", "require", "default"] } : {}
|
|
213
208
|
};
|
|
214
209
|
const optimization = !isServerBuild && !isDev ? {
|
|
215
210
|
moduleIds: "deterministic",
|