dom-expressions 0.37.3 → 0.37.5

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dom-expressions",
3
3
  "description": "A Fine-Grained Runtime for Performant DOM Rendering",
4
- "version": "0.37.3",
4
+ "version": "0.37.5",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -20,12 +20,12 @@
20
20
  },
21
21
  "peerDependencies": {
22
22
  "csstype": "^3.0",
23
- "seroval": "^0.11.4"
23
+ "seroval": "^0.12.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "babel-plugin-jsx-dom-expressions": "^0.37.2",
27
27
  "csstype": "^3.1",
28
- "seroval": "^0.11.4"
28
+ "seroval": "^0.12.0"
29
29
  },
30
- "gitHead": "812c7c5e8cd5143c0678ce93bd09f6eb9102b287"
30
+ "gitHead": "5bb950ad5fdd214d8e5d40a1911c60ea44cb2ef2"
31
31
  }
package/src/client.d.ts CHANGED
@@ -69,4 +69,8 @@ export function HydrationScript(): JSX.Element;
69
69
  export function generateHydrationScript(): string;
70
70
  export function Assets(props: { children?: JSX.Element }): JSX.Element;
71
71
  export function Hydration(props: { children?: JSX.Element }): JSX.Element;
72
- export function NoHydration(props: { children?: JSX.Element }): JSX.Element;
72
+ export function NoHydration(props: { children?: JSX.Element }): JSX.Element;
73
+ export interface RequestEvent {
74
+ request: Request;
75
+ }
76
+ export function getRequestEvent(): RequestEvent | undefined;
package/src/client.js CHANGED
@@ -41,7 +41,8 @@ export {
41
41
  voidFn as getAssets,
42
42
  voidFn as Assets,
43
43
  voidFn as generateHydrationScript,
44
- voidFn as HydrationScript
44
+ voidFn as HydrationScript,
45
+ voidFn as getRequestEvent
45
46
  };
46
47
 
47
48
  export function render(code, element, init, options = {}) {
package/src/serializer.js CHANGED
@@ -7,13 +7,14 @@ const ES2017FLAG =
7
7
 
8
8
  const GLOBAL_IDENTIFIER = '_$HY.r'; // TODO this is a pending name
9
9
 
10
- export function createSerializer({ onData, onDone, scopeId }) {
10
+ export function createSerializer({ onData, onDone, scopeId, onError }) {
11
11
  return new Serializer({
12
12
  scopeId,
13
13
  globalIdentifier: GLOBAL_IDENTIFIER,
14
14
  disabledFeatures: ES2017FLAG,
15
15
  onData,
16
16
  onDone,
17
+ onError,
17
18
  });
18
19
  }
19
20
 
package/src/server.d.ts CHANGED
@@ -3,6 +3,7 @@ export function renderToString<T>(
3
3
  options?: {
4
4
  nonce?: string;
5
5
  renderId?: string;
6
+ onError: (err: any) => void;
6
7
  }
7
8
  ): string;
8
9
  export function renderToStringAsync<T>(
@@ -11,6 +12,7 @@ export function renderToStringAsync<T>(
11
12
  timeoutMs?: number;
12
13
  nonce?: string;
13
14
  renderId?: string;
15
+ onError: (err: any) => void;
14
16
  }
15
17
  ): Promise<string>;
16
18
  export function renderToStream<T>(
@@ -20,6 +22,7 @@ export function renderToStream<T>(
20
22
  renderId?: string;
21
23
  onCompleteShell?: (info: { write: (v: string) => void }) => void;
22
24
  onCompleteAll?: (info: { write: (v: string) => void }) => void;
25
+ onError: (err: any) => void;
23
26
  }
24
27
  ): {
25
28
  pipe: (writable: { write: (v: string) => void }) => void;
@@ -49,7 +52,11 @@ export function createComponent<T>(Comp: (props: T) => JSX.Element, props: T): J
49
52
  export function mergeProps(...sources: unknown[]): unknown;
50
53
  export function getOwner(): unknown;
51
54
  export function generateHydrationScript(options: { nonce?: string; eventNames?: string[] }): string;
52
- export function stringify(root: unknown): string;
55
+ export declare const RequestContext: unique symbol;
56
+ export interface RequestEvent {
57
+ request: Request;
58
+ }
59
+ export function getRequestEvent(): RequestEvent | undefined;
53
60
 
54
61
  export function Hydration(props: { children?: JSX.Element }): JSX.Element;
55
62
  export function NoHydration(props: { children?: JSX.Element }): JSX.Element;
package/src/server.js CHANGED
@@ -18,7 +18,8 @@ export function renderToString(code, options = {}) {
18
18
  scripts = getLocalHeaderScript(renderId);
19
19
  }
20
20
  scripts += script;
21
- }
21
+ },
22
+ onError: options.onError
22
23
  });
23
24
  sharedConfig.context = {
24
25
  id: renderId || "",
@@ -27,6 +28,7 @@ export function renderToString(code, options = {}) {
27
28
  lazy: {},
28
29
  assets: [],
29
30
  nonce: options.nonce,
31
+ event: {},
30
32
  serialize(id, p) {
31
33
  !sharedConfig.context.noHydrate && serializer.write(id, p);
32
34
  }
@@ -85,7 +87,8 @@ export function renderToStream(code, options = {}) {
85
87
  const serializer = createSerializer({
86
88
  scopeId: options.renderId,
87
89
  onData: pushTask,
88
- onDone: checkEnd
90
+ onDone: checkEnd,
91
+ onError: options.onError
89
92
  });
90
93
  const flushEnd = () => {
91
94
  if (!registry.size) {
@@ -122,6 +125,7 @@ export function renderToStream(code, options = {}) {
122
125
  id: renderId || "",
123
126
  count: 0,
124
127
  async: true,
128
+ event: {},
125
129
  resources: {},
126
130
  lazy: {},
127
131
  suspense: {},
@@ -538,6 +542,17 @@ function replacePlaceholder(html, key, value) {
538
542
  return html.slice(0, first) + value + html.slice(last + close.length);
539
543
  }
540
544
 
545
+ // experimental
546
+ export const RequestContext = Symbol();
547
+
548
+ export function getRequestEvent() {
549
+ return (
550
+ (globalThis[RequestContext] && globalThis[RequestContext].getStore()) ||
551
+ (sharedConfig.context && sharedConfig.context.event) ||
552
+ undefined
553
+ );
554
+ }
555
+
541
556
  // consider deprecating
542
557
  export function Assets(props) {
543
558
  useAssets(() => props.children);