hadars 1.0.0 → 1.0.2

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.
@@ -3,6 +3,7 @@ import {
3
3
  Component,
4
4
  PureComponent,
5
5
  Suspense,
6
+ __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
6
7
  cloneElement,
7
8
  createContext,
8
9
  forwardRef,
@@ -12,6 +13,7 @@ import {
12
13
  renderPreflight,
13
14
  renderToStream,
14
15
  renderToString,
16
+ setReactVersion,
15
17
  slim_react_default,
16
18
  startTransition,
17
19
  use,
@@ -34,7 +36,7 @@ import {
34
36
  useSyncExternalStore,
35
37
  useTransition,
36
38
  version
37
- } from "../chunk-2TMQUXFL.js";
39
+ } from "../chunk-QOTDCUE5.js";
38
40
  import {
39
41
  FRAGMENT_TYPE,
40
42
  Fragment,
@@ -52,6 +54,7 @@ export {
52
54
  SLIM_ELEMENT,
53
55
  SUSPENSE_TYPE,
54
56
  Suspense,
57
+ __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
55
58
  cloneElement,
56
59
  createContext,
57
60
  createElement,
@@ -67,6 +70,7 @@ export {
67
70
  renderToStream as renderToReadableStream,
68
71
  renderToStream,
69
72
  renderToString,
73
+ setReactVersion,
70
74
  startTransition,
71
75
  use,
72
76
  useActionState,
@@ -7,24 +7,6 @@ var SLIM_ELEMENT = Symbol.for("react.element");
7
7
  var REACT19_ELEMENT = Symbol.for("react.transitional.element");
8
8
  var FRAGMENT_TYPE = Symbol.for("react.fragment");
9
9
  var SUSPENSE_TYPE = Symbol.for("react.suspense");
10
- // src/slim-react/jsx.ts
11
- function createElement(type, props, ...children) {
12
- const normalizedProps = { ...props || {} };
13
- if (children.length === 1) {
14
- normalizedProps.children = children[0];
15
- } else if (children.length > 1) {
16
- normalizedProps.children = children;
17
- }
18
- const key = normalizedProps.key ?? null;
19
- delete normalizedProps.key;
20
- return {
21
- $$typeof: SLIM_ELEMENT,
22
- type,
23
- props: normalizedProps,
24
- key
25
- };
26
- }
27
-
28
10
  // src/slim-react/renderContext.ts
29
11
  var MAP_KEY = "__slimReactContextMap";
30
12
  var _g = globalThis;
@@ -49,8 +31,7 @@ function getContextValue(context) {
49
31
  const map = _g[MAP_KEY];
50
32
  if (map && map.has(context))
51
33
  return map.get(context);
52
- const c = context;
53
- return "_defaultValue" in c ? c._defaultValue : c._currentValue;
34
+ return context._currentValue;
54
35
  }
55
36
  function pushContextValue(context, value) {
56
37
  let map = _g[MAP_KEY];
@@ -58,8 +39,7 @@ function pushContextValue(context, value) {
58
39
  map = new Map;
59
40
  _g[MAP_KEY] = map;
60
41
  }
61
- const c = context;
62
- const prev = map.has(context) ? map.get(context) : ("_defaultValue" in c) ? c._defaultValue : c._currentValue;
42
+ const prev = map.has(context) ? map.get(context) : context._currentValue;
63
43
  map.set(context, value);
64
44
  return prev;
65
45
  }
@@ -164,14 +144,35 @@ function getTreeId() {
164
144
  const stripped = (id & ~(1 << 31 - Math.clz32(id))).toString(32);
165
145
  return stripped + overflow;
166
146
  }
147
+ var REACT_MAJOR = typeof __HADARS_REACT_MAJOR__ !== "undefined" ? parseInt(String(__HADARS_REACT_MAJOR__), 10) : 19;
148
+ var REACT_VERSION = REACT_MAJOR < 19 ? "18.3.1" : "19.1.1";
167
149
  function makeId() {
168
150
  const st = s();
169
151
  const treeId = getTreeId();
170
152
  const n = st.localIdCounter++;
171
- let id = "_R_" + st.idPrefix + treeId;
172
- if (n > 0)
173
- id += "H" + n.toString(32);
174
- return id + "_";
153
+ const suffix = n > 0 ? "H" + n.toString(32) : "";
154
+ if (REACT_MAJOR < 19) {
155
+ return ":" + st.idPrefix + "R" + treeId + suffix + ":";
156
+ }
157
+ return "_R_" + st.idPrefix + treeId + suffix + "_";
158
+ }
159
+
160
+ // src/slim-react/jsx.ts
161
+ function createElement(type, props, ...children) {
162
+ const normalizedProps = { ...props || {} };
163
+ if (children.length === 1) {
164
+ normalizedProps.children = children[0];
165
+ } else if (children.length > 1) {
166
+ normalizedProps.children = children;
167
+ }
168
+ const key = normalizedProps.key ?? null;
169
+ delete normalizedProps.key;
170
+ return {
171
+ $$typeof: SLIM_ELEMENT,
172
+ type,
173
+ props: normalizedProps,
174
+ key
175
+ };
175
176
  }
176
177
 
177
178
  // src/slim-react/hooks.ts
@@ -224,8 +225,24 @@ function use(usable) {
224
225
  }
225
226
  // src/slim-react/dispatcher.ts
226
227
  import * as ReactNS from "react";
227
- var _reactInternalsKey = "__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE";
228
- var _internals = ReactNS[_reactInternalsKey];
228
+ var _r19;
229
+ var _r18;
230
+ var _detected = false;
231
+ var _k19 = "__CLIENT_INTERNALS_DO_NOT_USE" + "_OR_WARN_USERS_THEY_CANNOT_UPGRADE";
232
+ var _k18 = "__SECRET_INTERNALS_DO_NOT_USE" + "_OR_YOU_WILL_BE_FIRED";
233
+ function _detect() {
234
+ if (_detected)
235
+ return;
236
+ _detected = true;
237
+ const r19 = ReactNS[_k19];
238
+ if (r19) {
239
+ _r19 = r19;
240
+ return;
241
+ }
242
+ const raw = ReactNS[_k18];
243
+ if (raw?.ReactCurrentDispatcher)
244
+ _r18 = raw;
245
+ }
229
246
  var slimDispatcher = {
230
247
  useId: makeId,
231
248
  readContext: (ctx) => getContextValue(ctx),
@@ -251,15 +268,25 @@ var slimDispatcher = {
251
268
  useHostTransitionStatus: () => false
252
269
  };
253
270
  function installDispatcher() {
254
- if (!_internals)
255
- return null;
256
- const prev = _internals.H;
257
- _internals.H = slimDispatcher;
258
- return prev;
271
+ _detect();
272
+ if (_r19) {
273
+ const prev = _r19.H;
274
+ _r19.H = slimDispatcher;
275
+ return prev;
276
+ }
277
+ if (_r18) {
278
+ const prev = _r18.ReactCurrentDispatcher.current;
279
+ _r18.ReactCurrentDispatcher.current = slimDispatcher;
280
+ return prev;
281
+ }
282
+ return null;
259
283
  }
260
284
  function restoreDispatcher(prev) {
261
- if (_internals)
262
- _internals.H = prev;
285
+ _detect();
286
+ if (_r19)
287
+ _r19.H = prev;
288
+ else if (_r18)
289
+ _r18.ReactCurrentDispatcher.current = prev;
263
290
  }
264
291
 
265
292
  // src/slim-react/render.ts
@@ -520,7 +547,7 @@ function writeAttributes(writer, props, isSvg, skip) {
520
547
  if (isSvg && key in SVG_ATTR_MAP) {
521
548
  attrName = SVG_ATTR_MAP[key];
522
549
  } else {
523
- attrName = key === "className" ? "class" : key === "htmlFor" ? "for" : key === "tabIndex" ? "tabindex" : key === "defaultValue" ? "value" : key === "defaultChecked" ? "checked" : key;
550
+ attrName = key === "className" ? "class" : key === "htmlFor" ? "for" : key === "tabIndex" ? "tabindex" : key === "defaultValue" ? "value" : key === "defaultChecked" ? "checked" : key === "contentEditable" && REACT_MAJOR < 19 ? "contenteditable" : key;
524
551
  }
525
552
  if (value === false || value == null) {
526
553
  if (value === false && (attrName.charCodeAt(0) === 97 && attrName.startsWith("aria-") || attrName.charCodeAt(0) === 100 && attrName.startsWith("data-"))) {
@@ -731,7 +758,8 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
731
758
  const LazyComp = resolved?.default ?? resolved;
732
759
  return renderComponent(LazyComp, props, writer, isSvg);
733
760
  }
734
- if (typeOf === REACT_CONSUMER) {
761
+ const isConsumer = typeOf === REACT_CONSUMER || typeOf === REACT_CONTEXT && "_context" in type && !("value" in props);
762
+ if (isConsumer) {
735
763
  const ctx2 = type._context;
736
764
  const value = ctx2 ? getContextValue(ctx2) : undefined;
737
765
  const result2 = typeof props.children === "function" ? props.children(value) : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hadars",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Minimal SSR framework for React — rspack, HMR, TypeScript, Bun/Node/Deno",
5
5
  "module": "./dist/index.js",
6
6
  "type": "module",
@@ -58,8 +58,8 @@
58
58
  "node": ">=18.0.0"
59
59
  },
60
60
  "peerDependencies": {
61
- "react": "^19.2.0",
62
- "react-dom": "^19.2.0",
61
+ "react": "^18.0.0 || ^19.0.0",
62
+ "react-dom": "^18.0.0 || ^19.0.0",
63
63
  "typescript": "^5"
64
64
  },
65
65
  "peerDependenciesMeta": {