hadars 0.1.40 → 0.2.1

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.
Files changed (42) hide show
  1. package/README.md +85 -70
  2. package/cli-lib.ts +89 -12
  3. package/dist/chunk-HWOLYLPF.js +332 -0
  4. package/dist/{chunk-2ENP7IAW.js → chunk-LY5MTHFV.js} +360 -203
  5. package/dist/cli.js +506 -274
  6. package/dist/cloudflare.cjs +1394 -0
  7. package/dist/cloudflare.d.cts +64 -0
  8. package/dist/cloudflare.d.ts +64 -0
  9. package/dist/cloudflare.js +68 -0
  10. package/dist/{hadars-Bh-V5YXg.d.cts → hadars-DEBSYAQl.d.cts} +1 -36
  11. package/dist/{hadars-Bh-V5YXg.d.ts → hadars-DEBSYAQl.d.ts} +1 -36
  12. package/dist/index.cjs +129 -156
  13. package/dist/index.d.cts +5 -11
  14. package/dist/index.d.ts +5 -11
  15. package/dist/index.js +129 -155
  16. package/dist/lambda.cjs +391 -229
  17. package/dist/lambda.d.cts +1 -2
  18. package/dist/lambda.d.ts +1 -2
  19. package/dist/lambda.js +18 -307
  20. package/dist/slim-react/index.cjs +361 -203
  21. package/dist/slim-react/index.d.cts +24 -8
  22. package/dist/slim-react/index.d.ts +24 -8
  23. package/dist/slim-react/index.js +3 -1
  24. package/dist/ssr-render-worker.js +352 -221
  25. package/dist/utils/Head.tsx +132 -187
  26. package/package.json +7 -2
  27. package/src/build.ts +7 -6
  28. package/src/cloudflare.ts +139 -0
  29. package/src/index.tsx +0 -3
  30. package/src/lambda.ts +6 -2
  31. package/src/slim-react/context.ts +2 -1
  32. package/src/slim-react/index.ts +21 -18
  33. package/src/slim-react/render.ts +379 -240
  34. package/src/slim-react/renderContext.ts +105 -45
  35. package/src/ssr-render-worker.ts +14 -44
  36. package/src/types/hadars.ts +0 -1
  37. package/src/utils/Head.tsx +132 -187
  38. package/src/utils/cookies.ts +1 -1
  39. package/src/utils/response.tsx +68 -33
  40. package/src/utils/serve.ts +29 -27
  41. package/src/utils/ssrHandler.ts +54 -25
  42. package/src/utils/staticFile.ts +2 -7
@@ -1,4 +1,5 @@
1
1
  import type { SlimNode } from "./types";
2
+ import { getContextValue } from "./renderContext";
2
3
 
3
4
  /**
4
5
  * Minimal Context implementation for SSR.
@@ -46,7 +47,7 @@ export function createContext<T>(defaultValue: T): Context<T> {
46
47
 
47
48
  context.Consumer = ({ children }) => {
48
49
  return (children as unknown as (value: T) => SlimNode)(
49
- context._currentValue,
50
+ getContextValue<T>(context),
50
51
  );
51
52
  };
52
53
 
@@ -74,22 +74,20 @@ export function useContext<T>(context: Context<T>): T {
74
74
  }
75
75
 
76
76
  // ---- Rendering ----
77
- import { renderToStream, renderToString, renderToReadableStream } from "./render";
78
- export { renderToStream, renderToString, renderToReadableStream, type RenderOptions } from "./render";
77
+ import { renderToStream, renderToString, renderToReadableStream, renderPreflight } from "./render";
78
+ export { renderToStream, renderToString, renderToReadableStream, renderPreflight, type RenderOptions } from "./render";
79
79
 
80
80
  // ---- Suspense (as a JSX tag) ----
81
81
  import { SUSPENSE_TYPE } from "./types";
82
82
  export const Suspense = SUSPENSE_TYPE;
83
83
 
84
84
  // ---- Compat utilities ----
85
- import { SLIM_ELEMENT, type SlimElement, type SlimNode } from "./types";
85
+ import { SLIM_ELEMENT, REACT19_ELEMENT, type SlimElement, type SlimNode } from "./types";
86
86
 
87
87
  export function isValidElement(obj: unknown): obj is SlimElement {
88
- return (
89
- typeof obj === "object" &&
90
- obj !== null &&
91
- (obj as any).$$typeof === SLIM_ELEMENT
92
- );
88
+ if (typeof obj !== "object" || obj === null) return false;
89
+ const t = (obj as any).$$typeof;
90
+ return t === SLIM_ELEMENT || t === REACT19_ELEMENT;
93
91
  }
94
92
 
95
93
  export function cloneElement(
@@ -98,7 +96,7 @@ export function cloneElement(
98
96
  ...children: SlimNode[]
99
97
  ): SlimElement {
100
98
  return {
101
- $$typeof: SLIM_ELEMENT,
99
+ $$typeof: (element as any).$$typeof || SLIM_ELEMENT,
102
100
  type: element.type,
103
101
  props: {
104
102
  ...element.props,
@@ -115,18 +113,23 @@ export function cloneElement(
115
113
 
116
114
  export function forwardRef<P = any>(
117
115
  render: (props: P, ref: any) => SlimNode,
118
- ): (props: P & { ref?: any }) => SlimNode {
119
- const component = (props: P & { ref?: any }) =>
120
- render(props, (props as any).ref ?? null);
121
- (component as any).displayName =
122
- (render as any).displayName || (render as any).name || "ForwardRef";
123
- return component;
116
+ ): any {
117
+ return {
118
+ $$typeof: Symbol.for("react.forward_ref"),
119
+ render,
120
+ displayName: (render as any).displayName || (render as any).name || "ForwardRef",
121
+ };
124
122
  }
125
123
 
126
124
  export function memo<P = any>(
127
125
  component: (props: P) => SlimNode,
128
- ): (props: P) => SlimNode {
129
- return component; // no memoisation needed for SSR
126
+ compare?: (prevProps: P, nextProps: P) => boolean,
127
+ ): any {
128
+ return {
129
+ $$typeof: Symbol.for("react.memo"),
130
+ type: component,
131
+ compare: compare ?? null,
132
+ };
130
133
  }
131
134
 
132
135
  export function lazy<P = any>(
@@ -221,7 +224,7 @@ const React = {
221
224
  // Compat
222
225
  Children, Component, PureComponent,
223
226
  // Rendering
224
- renderToStream, renderToString, renderToReadableStream,
227
+ renderToStream, renderToString, renderToReadableStream, renderPreflight,
225
228
  // Version
226
229
  version,
227
230
  };