@quilted/quilt 0.6.11 → 0.6.13

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 (58) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/build/esm/react.mjs +1 -2
  3. package/build/esm/server/ServerContext.mjs +18 -2
  4. package/build/esm/server/request-router.mjs +25 -57
  5. package/build/esm/server.mjs +1 -2
  6. package/build/esnext/react.esnext +1 -2
  7. package/build/esnext/server/ServerContext.esnext +6 -14
  8. package/build/esnext/server/request-router.esnext +28 -37
  9. package/build/esnext/server.esnext +1 -2
  10. package/build/tsconfig.tsbuildinfo +1 -1
  11. package/build/typescript/react.d.ts +1 -2
  12. package/build/typescript/react.d.ts.map +1 -1
  13. package/build/typescript/request-router.d.ts +2 -0
  14. package/build/typescript/request-router.d.ts.map +1 -0
  15. package/build/typescript/server/ServerContext.d.ts +1 -1
  16. package/build/typescript/server/ServerContext.d.ts.map +1 -1
  17. package/build/typescript/server/request-router.d.ts +10 -6
  18. package/build/typescript/server/request-router.d.ts.map +1 -1
  19. package/build/typescript/server.d.ts +1 -2
  20. package/build/typescript/server.d.ts.map +1 -1
  21. package/package.json +9 -19
  22. package/source/react.ts +1 -4
  23. package/source/server/ServerContext.tsx +30 -14
  24. package/source/server/request-router.tsx +41 -53
  25. package/source/server.ts +1 -8
  26. package/tsconfig.json +0 -1
  27. package/build/esm/react/tools.mjs +0 -2
  28. package/build/esm/server/preload.mjs +0 -35
  29. package/build/esm/utilities/react.mjs +0 -10
  30. package/build/esnext/react/tools.esnext +0 -2
  31. package/build/esnext/server/preload.esnext +0 -34
  32. package/build/esnext/utilities/react.esnext +0 -7
  33. package/build/typescript/react/jsx-runtime.d.ts +0 -2
  34. package/build/typescript/react/jsx-runtime.d.ts.map +0 -1
  35. package/build/typescript/react/tools.d.ts +0 -3
  36. package/build/typescript/react/tools.d.ts.map +0 -1
  37. package/build/typescript/react-dom/server.d.ts +0 -2
  38. package/build/typescript/react-dom/server.d.ts.map +0 -1
  39. package/build/typescript/react-dom/test-utils.d.ts +0 -2
  40. package/build/typescript/react-dom/test-utils.d.ts.map +0 -1
  41. package/build/typescript/react-dom.d.ts +0 -3
  42. package/build/typescript/react-dom.d.ts.map +0 -1
  43. package/build/typescript/request-router/index.d.ts +0 -2
  44. package/build/typescript/request-router/index.d.ts.map +0 -1
  45. package/build/typescript/server/preload.d.ts +0 -8
  46. package/build/typescript/server/preload.d.ts.map +0 -1
  47. package/build/typescript/utilities/react.d.ts +0 -3
  48. package/build/typescript/utilities/react.d.ts.map +0 -1
  49. package/source/react/jsx-runtime.ts +0 -2
  50. package/source/react/tools.ts +0 -2
  51. package/source/react-dom/server.ts +0 -2
  52. package/source/react-dom/test-utils.ts +0 -2
  53. package/source/react-dom.ts +0 -4
  54. package/source/server/preload.ts +0 -69
  55. package/source/utilities/react.tsx +0 -13
  56. /package/build/esm/{request-router/index.mjs → request-router.mjs} +0 -0
  57. /package/build/esnext/{request-router/index.esnext → request-router.esnext} +0 -0
  58. /package/source/{request-router/index.ts → request-router.ts} +0 -0
@@ -1,3 +1,2 @@
1
- export * from '@quilted/react';
2
- export { default } from '@quilted/react';
1
+ export * from '@quilted/react-utilities';
3
2
  //# sourceMappingURL=react.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../source/react.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../source/react.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from '@quilted/request-router';
2
+ //# sourceMappingURL=request-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-router.d.ts","sourceRoot":"","sources":["../../source/request-router.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
@@ -8,6 +8,6 @@ interface Props {
8
8
  http?: HttpManager;
9
9
  assets?: AssetsManager;
10
10
  }
11
- export declare function ServerContext({ url, html, http, assets, children, }: PropsWithChildren<Props>): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
11
+ export declare function ServerContext({ url, html, http, assets, children, }: PropsWithChildren<Props>): string | number | boolean | Iterable<import("react").ReactNode> | import("react").JSX.Element | null | undefined;
12
12
  export {};
13
13
  //# sourceMappingURL=ServerContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ServerContext.d.ts","sourceRoot":"","sources":["../../../source/server/ServerContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAgB,KAAK,aAAa,EAAC,MAAM,8BAA8B,CAAC;AAE/E,OAAO,EAAc,KAAK,WAAW,EAAC,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAoB,KAAK,WAAW,EAAC,MAAM,4BAA4B,CAAC;AAI/E,UAAU,KAAK;IACb,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED,wBAAgB,aAAa,CAAC,EAC5B,GAAG,EACH,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,QAAQ,GACT,EAAE,iBAAiB,CAAC,KAAK,CAAC,0FAgB1B"}
1
+ {"version":3,"file":"ServerContext.d.ts","sourceRoot":"","sources":["../../../source/server/ServerContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAgB,KAAK,aAAa,EAAC,MAAM,8BAA8B,CAAC;AAE/E,OAAO,EAAc,KAAK,WAAW,EAAC,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAoB,KAAK,WAAW,EAAC,MAAM,4BAA4B,CAAC;AAE/E,UAAU,KAAK;IACb,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED,wBAAgB,aAAa,CAAC,EAC5B,GAAG,EACH,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,QAAQ,GACT,EAAE,iBAAiB,CAAC,KAAK,CAAC,oHAkC1B"}
@@ -2,19 +2,23 @@ import { type ReactElement } from 'react';
2
2
  import { type AssetsCacheKey, type BrowserAssets, type BrowserAssetsEntry } from '@quilted/assets';
3
3
  import { HTMLManager } from '@quilted/react-html/server';
4
4
  import { HTMLResponse, RedirectResponse } from '@quilted/request-router';
5
+ export interface RenderHTMLFunction {
6
+ (content: ReadableStream<string>, context: {
7
+ readonly manager: HTMLManager;
8
+ readonly headers: Headers;
9
+ readonly assets?: BrowserAssetsEntry;
10
+ readonly preloadAssets?: BrowserAssetsEntry;
11
+ }): ReadableStream<any> | string | Promise<ReadableStream<any> | string>;
12
+ }
5
13
  export interface RenderOptions<CacheKey = AssetsCacheKey> {
6
14
  readonly request: Request;
7
15
  readonly stream?: 'headers' | false;
16
+ readonly headers?: HeadersInit;
8
17
  readonly assets?: BrowserAssets<CacheKey>;
9
18
  readonly cacheKey?: CacheKey;
19
+ readonly renderHTML?: boolean | 'fragment' | 'document' | RenderHTMLFunction;
10
20
  waitUntil?(promise: Promise<any>): void;
11
- renderHTML?(content: ReadableStream<string>, context: {
12
- readonly manager: HTMLManager;
13
- readonly assets?: BrowserAssetsEntry;
14
- readonly preloadAssets?: BrowserAssetsEntry;
15
- }): ReadableStream<any> | Promise<ReadableStream<any>>;
16
21
  }
17
- export declare function renderToFragmentResponse(element: ReactElement<any>, { request }: Pick<RenderOptions<any>, 'request'>): Promise<RedirectResponse | HTMLResponse>;
18
22
  export declare function renderToResponse<CacheKey = AssetsCacheKey>(element: ReactElement<any>, options: RenderOptions<CacheKey>): Promise<HTMLResponse | RedirectResponse>;
19
23
  export declare function renderToResponse<CacheKey = AssetsCacheKey>(options: RenderOptions<CacheKey>): Promise<HTMLResponse | RedirectResponse>;
20
24
  //# sourceMappingURL=request-router.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"request-router.d.ts","sourceRoot":"","sources":["../../../source/server/request-router.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,YAAY,EAAC,MAAM,OAAO,CAAC;AAGxD,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAML,WAAW,EACZ,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAC,YAAY,EAAE,gBAAgB,EAAC,MAAM,yBAAyB,CAAC;AAIvE,MAAM,WAAW,aAAa,CAAC,QAAQ,GAAG,cAAc;IACtD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,KAAK,CAAC;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC1C,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B,SAAS,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACxC,UAAU,CAAC,CACT,OAAO,EAAE,cAAc,CAAC,MAAM,CAAC,EAC/B,OAAO,EAAE;QACP,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;QAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB,CAAC;QACrC,QAAQ,CAAC,aAAa,CAAC,EAAE,kBAAkB,CAAC;KAC7C,GACA,cAAc,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;CACvD;AAED,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,EAC1B,EAAC,OAAO,EAAC,EAAE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,4CA8B/C;AAED,wBAAsB,gBAAgB,CAAC,QAAQ,GAAG,cAAc,EAC9D,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,EAC1B,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,GAC/B,OAAO,CAAC,YAAY,GAAG,gBAAgB,CAAC,CAAC;AAC5C,wBAAsB,gBAAgB,CAAC,QAAQ,GAAG,cAAc,EAC9D,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,GAC/B,OAAO,CAAC,YAAY,GAAG,gBAAgB,CAAC,CAAC"}
1
+ {"version":3,"file":"request-router.d.ts","sourceRoot":"","sources":["../../../source/server/request-router.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,YAAY,EAAC,MAAM,OAAO,CAAC;AAGxD,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAML,WAAW,EACZ,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAC,YAAY,EAAE,gBAAgB,EAAC,MAAM,yBAAyB,CAAC;AAIvE,MAAM,WAAW,kBAAkB;IACjC,CACE,OAAO,EAAE,cAAc,CAAC,MAAM,CAAC,EAC/B,OAAO,EAAE;QACP,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;QAC9B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;QAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB,CAAC;QACrC,QAAQ,CAAC,aAAa,CAAC,EAAE,kBAAkB,CAAC;KAC7C,GACA,cAAc,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;CACzE;AAED,MAAM,WAAW,aAAa,CAAC,QAAQ,GAAG,cAAc;IACtD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,KAAK,CAAC;IACpC,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC1C,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,UAAU,GAAG,kBAAkB,CAAC;IAC7E,SAAS,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;CACzC;AAED,wBAAsB,gBAAgB,CAAC,QAAQ,GAAG,cAAc,EAC9D,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,EAC1B,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,GAC/B,OAAO,CAAC,YAAY,GAAG,gBAAgB,CAAC,CAAC;AAC5C,wBAAsB,gBAAgB,CAAC,QAAQ,GAAG,cAAc,EAC9D,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,GAC/B,OAAO,CAAC,YAAY,GAAG,gBAAgB,CAAC,CAAC"}
@@ -9,6 +9,5 @@ export { createRequestRouterLocalization } from '@quilted/react-localize/request
9
9
  export { ServerAction, useServerAction, useServerContext, } from '@quilted/react-server-render';
10
10
  export type { ServerActionKind, ServerActionOptions, ServerActionPerform, ServerRenderPass, ServerRenderRequestContext, } from '@quilted/react-server-render';
11
11
  export { ServerContext } from './server/ServerContext.tsx';
12
- export { renderToResponse, renderToFragmentResponse, } from './server/request-router.tsx';
13
- export { createAssetPreloader, type AssetPreloadOptions, } from './server/preload.ts';
12
+ export { renderToResponse } from './server/request-router.tsx';
14
13
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../source/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,SAAS,EACT,WAAW,EACX,WAAW,EACX,gBAAgB,IAAI,qBAAqB,GAC1C,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,EACrB,4BAA4B,EAC5B,0BAA0B,EAC1B,oCAAoC,GACrC,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,KAAK,EACL,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,EAC1B,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,aAAa,EACb,gBAAgB,IAAI,uBAAuB,GAC5C,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAC,SAAS,EAAC,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAC,yBAAyB,EAAC,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAC,+BAA+B,EAAC,MAAM,wCAAwC,CAAC;AACvF,OAAO,EACL,YAAY,EACZ,eAAe,EACf,gBAAgB,GACjB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,0BAA0B,GAC3B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AACzD,OAAO,EACL,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,oBAAoB,EACpB,KAAK,mBAAmB,GACzB,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../source/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,SAAS,EACT,WAAW,EACX,WAAW,EACX,gBAAgB,IAAI,qBAAqB,GAC1C,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,EACrB,4BAA4B,EAC5B,0BAA0B,EAC1B,oCAAoC,GACrC,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,KAAK,EACL,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,EAC1B,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,aAAa,EACb,gBAAgB,IAAI,uBAAuB,GAC5C,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAC,SAAS,EAAC,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAC,yBAAyB,EAAC,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAC,+BAA+B,EAAC,MAAM,wCAAwC,CAAC;AACvF,OAAO,EACL,YAAY,EACZ,eAAe,EACf,gBAAgB,GACjB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,0BAA0B,GAC3B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quilted/quilt",
3
3
  "type": "module",
4
- "version": "0.6.11",
4
+ "version": "0.6.13",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/lemonmade/quilt.git",
@@ -97,12 +97,6 @@
97
97
  "quilt:esnext": "./build/esnext/react/testing.esnext",
98
98
  "import": "./build/esm/react/testing.mjs"
99
99
  },
100
- "./react/tools": {
101
- "types": "./build/typescript/react/tools.d.ts",
102
- "quilt:source": "./source/react/tools.ts",
103
- "quilt:esnext": "./build/esnext/react/tools.esnext",
104
- "import": "./build/esm/react/tools.mjs"
105
- },
106
100
  "./graphql": {
107
101
  "types": "./build/typescript/graphql.d.ts",
108
102
  "quilt:source": "./source/graphql.ts",
@@ -134,10 +128,10 @@
134
128
  "import": "./build/esm/env.mjs"
135
129
  },
136
130
  "./request-router": {
137
- "types": "./build/typescript/request-router/index.d.ts",
138
- "quilt:source": "./source/request-router/index.ts",
139
- "quilt:esnext": "./build/esnext/request-router/index.esnext",
140
- "import": "./build/esm/request-router/index.mjs"
131
+ "types": "./build/typescript/request-router.d.ts",
132
+ "quilt:source": "./source/request-router.ts",
133
+ "quilt:esnext": "./build/esnext/request-router.esnext",
134
+ "import": "./build/esm/request-router.mjs"
141
135
  },
142
136
  "./request-router/node": {
143
137
  "types": "./build/typescript/request-router/node.d.ts",
@@ -221,9 +215,6 @@
221
215
  "react/testing": [
222
216
  "./build/typescript/react/testing.d.ts"
223
217
  ],
224
- "react/tools": [
225
- "./build/typescript/react/tools.d.ts"
226
- ],
227
218
  "modules": [
228
219
  "./build/typescript/modules.d.ts"
229
220
  ]
@@ -258,12 +249,11 @@
258
249
  "@quilted/request-router": "^0.2.0",
259
250
  "@quilted/signals": "^0.2.0",
260
251
  "@quilted/threads": "^2.0.0",
261
- "@quilted/useful-react-types": "^2.0.0",
262
252
  "jest-matcher-utils": "^29.0.0"
263
253
  },
264
254
  "peerDependencies": {
265
255
  "graphql": "^16.7.0",
266
- "preact": "^10.19.0",
256
+ "preact": "^10.20.0",
267
257
  "prettier": "^2.0.0 || ^3.0.0",
268
258
  "react": "^18.0.0",
269
259
  "react-dom": "^18.0.0",
@@ -290,12 +280,12 @@
290
280
  }
291
281
  },
292
282
  "devDependencies": {
293
- "@types/prettier": "^2.0.0",
294
283
  "expect": "^29.0.0",
295
- "preact": "^10.19.0",
284
+ "preact": "^10.20.0",
285
+ "prettier": "^3.2.0",
296
286
  "react": "npm:@quilted/react@^18.2.0",
297
287
  "react-dom": "npm:@quilted/react-dom@^18.2.0",
298
- "vitest": "^1.1.0"
288
+ "vitest": "^1.4.0"
299
289
  },
300
290
  "scripts": {
301
291
  "build": "rollup --config configuration/rollup.config.js"
package/source/react.ts CHANGED
@@ -1,4 +1 @@
1
- // @ts-expect-error not used for types
2
- export * from '@quilted/react';
3
- // @ts-expect-error not used for types
4
- export {default} from '@quilted/react';
1
+ export * from '@quilted/react-utilities';
@@ -5,8 +5,6 @@ import {InitialUrlContext} from '@quilted/react-router';
5
5
  import {HTMLContext, type HTMLManager} from '@quilted/react-html/server';
6
6
  import {HttpServerContext, type HttpManager} from '@quilted/react-http/server';
7
7
 
8
- import {maybeWrapContext} from '../utilities/react.tsx';
9
-
10
8
  interface Props {
11
9
  url?: string | URL;
12
10
  html?: HTMLManager;
@@ -23,17 +21,35 @@ export function ServerContext({
23
21
  }: PropsWithChildren<Props>) {
24
22
  const normalizedUrl = typeof url === 'string' ? new URL(url) : url;
25
23
 
26
- return maybeWrapContext(
27
- AssetsContext,
28
- assets,
29
- maybeWrapContext(
30
- HttpServerContext,
31
- http,
32
- maybeWrapContext(
33
- HTMLContext,
34
- html,
35
- maybeWrapContext(InitialUrlContext, normalizedUrl, children),
36
- ),
37
- ),
24
+ const withInitialURL = normalizedUrl ? (
25
+ <InitialUrlContext.Provider value={normalizedUrl}>
26
+ {children}
27
+ </InitialUrlContext.Provider>
28
+ ) : (
29
+ children
30
+ );
31
+
32
+ const withHTML = html ? (
33
+ <HTMLContext.Provider value={html}>{withInitialURL}</HTMLContext.Provider>
34
+ ) : (
35
+ withInitialURL
36
+ );
37
+
38
+ const withHTTPServer = http ? (
39
+ <HttpServerContext.Provider value={http}>
40
+ {withHTML}
41
+ </HttpServerContext.Provider>
42
+ ) : (
43
+ withHTML
44
+ );
45
+
46
+ const withAssets = assets ? (
47
+ <AssetsContext.Provider value={assets}>
48
+ {withHTTPServer}
49
+ </AssetsContext.Provider>
50
+ ) : (
51
+ withHTTPServer
38
52
  );
53
+
54
+ return withAssets;
39
55
  }
@@ -24,54 +24,26 @@ import {HTMLResponse, RedirectResponse} from '@quilted/request-router';
24
24
 
25
25
  import {ServerContext} from './ServerContext.tsx';
26
26
 
27
- export interface RenderOptions<CacheKey = AssetsCacheKey> {
28
- readonly request: Request;
29
- readonly stream?: 'headers' | false;
30
- readonly assets?: BrowserAssets<CacheKey>;
31
- readonly cacheKey?: CacheKey;
32
- waitUntil?(promise: Promise<any>): void;
33
- renderHTML?(
27
+ export interface RenderHTMLFunction {
28
+ (
34
29
  content: ReadableStream<string>,
35
30
  context: {
36
31
  readonly manager: HTMLManager;
32
+ readonly headers: Headers;
37
33
  readonly assets?: BrowserAssetsEntry;
38
34
  readonly preloadAssets?: BrowserAssetsEntry;
39
35
  },
40
- ): ReadableStream<any> | Promise<ReadableStream<any>>;
36
+ ): ReadableStream<any> | string | Promise<ReadableStream<any> | string>;
41
37
  }
42
38
 
43
- export async function renderToFragmentResponse(
44
- element: ReactElement<any>,
45
- {request}: Pick<RenderOptions<any>, 'request'>,
46
- ) {
47
- const baseUrl = (request as any).URL ?? new URL(request.url);
48
- const html = new HTMLManager();
49
- const http = new HttpManager({headers: request.headers});
50
-
51
- const rendered = await extract(element, {
52
- decorate(element) {
53
- return (
54
- <ServerContext http={http} html={html} url={baseUrl}>
55
- {element}
56
- </ServerContext>
57
- );
58
- },
59
- });
60
-
61
- const {headers, statusCode = 200, redirectUrl} = http.state;
62
-
63
- if (redirectUrl) {
64
- return new RedirectResponse(redirectUrl, {
65
- status: statusCode as 301,
66
- headers,
67
- request,
68
- });
69
- }
70
-
71
- return new HTMLResponse(rendered ?? '', {
72
- status: statusCode,
73
- headers,
74
- });
39
+ export interface RenderOptions<CacheKey = AssetsCacheKey> {
40
+ readonly request: Request;
41
+ readonly stream?: 'headers' | false;
42
+ readonly headers?: HeadersInit;
43
+ readonly assets?: BrowserAssets<CacheKey>;
44
+ readonly cacheKey?: CacheKey;
45
+ readonly renderHTML?: boolean | 'fragment' | 'document' | RenderHTMLFunction;
46
+ waitUntil?(promise: Promise<any>): void;
75
47
  }
76
48
 
77
49
  export async function renderToResponse<CacheKey = AssetsCacheKey>(
@@ -97,11 +69,12 @@ export async function renderToResponse<CacheKey = AssetsCacheKey>(
97
69
 
98
70
  const {
99
71
  request,
100
- stream: shouldStream = false,
101
72
  assets,
102
73
  cacheKey: explicitCacheKey,
74
+ headers: explicitHeaders,
103
75
  waitUntil = noop,
104
- renderHTML,
76
+ stream: shouldStream = false,
77
+ renderHTML = true,
105
78
  } = options;
106
79
 
107
80
  const baseUrl = (request as any).URL ?? new URL(request.url);
@@ -115,8 +88,8 @@ export async function renderToResponse<CacheKey = AssetsCacheKey>(
115
88
  const assetsManager = new AssetsManager<CacheKey>({cacheKey});
116
89
 
117
90
  let responseStatus = 200;
118
- let appHeaders: Headers | undefined;
119
91
  let appStream: ReadableStream<any> | undefined;
92
+ const headers = new Headers(explicitHeaders);
120
93
 
121
94
  if (shouldStream === false && element != null) {
122
95
  const rendered = await extract(element, {
@@ -134,17 +107,29 @@ export async function renderToResponse<CacheKey = AssetsCacheKey>(
134
107
  },
135
108
  });
136
109
 
137
- const {headers, statusCode = 200, redirectUrl} = http.state;
110
+ const {headers: appHeaders, statusCode = 200, redirectUrl} = http.state;
111
+
112
+ const hasSetCookieHeader = typeof appHeaders.getSetCookie === 'function';
113
+
114
+ if (hasSetCookieHeader) {
115
+ for (const cookie of appHeaders.getSetCookie()) {
116
+ headers.append('Set-Cookie', cookie);
117
+ }
118
+ }
119
+
120
+ for (const [header, value] of appHeaders.entries()) {
121
+ if (hasSetCookieHeader && header.toLowerCase() === 'set-cookie') continue;
122
+ headers.set(header, value);
123
+ }
138
124
 
139
125
  if (redirectUrl) {
140
126
  return new RedirectResponse(redirectUrl, {
141
127
  status: statusCode as 301,
142
- headers,
128
+ headers: headers,
143
129
  request,
144
130
  });
145
131
  }
146
132
 
147
- appHeaders = headers;
148
133
  responseStatus = statusCode;
149
134
 
150
135
  const appTransformStream = new TransformStream();
@@ -187,16 +172,16 @@ export async function renderToResponse<CacheKey = AssetsCacheKey>(
187
172
  waitUntil(renderAppStream());
188
173
  }
189
174
 
190
- const {headers, body} = await renderToHTMLStream(appStream);
175
+ const body = await renderToHTMLBody(appStream);
191
176
 
192
177
  return new HTMLResponse(body, {
193
178
  status: responseStatus,
194
179
  headers,
195
180
  });
196
181
 
197
- async function renderToHTMLStream(content: ReadableStream<any>) {
198
- const headers = new Headers(appHeaders);
199
-
182
+ async function renderToHTMLBody(
183
+ content: ReadableStream<any>,
184
+ ): Promise<ReadableStream<any> | string> {
200
185
  const [synchronousAssets, preloadAssets] = await Promise.all([
201
186
  assets?.entry({
202
187
  cacheKey,
@@ -223,14 +208,17 @@ export async function renderToResponse<CacheKey = AssetsCacheKey>(
223
208
  }
224
209
  }
225
210
 
226
- if (renderHTML) {
211
+ if (typeof renderHTML === 'function') {
227
212
  const body = await renderHTML(content, {
228
213
  manager: html,
214
+ headers,
229
215
  assets: synchronousAssets,
230
216
  preloadAssets,
231
217
  });
232
218
 
233
- return {headers, body};
219
+ return body;
220
+ } else if (renderHTML === false || renderHTML === 'fragment') {
221
+ return content;
234
222
  }
235
223
 
236
224
  const responseStream = new TextEncoderStream();
@@ -347,7 +335,7 @@ export async function renderToResponse<CacheKey = AssetsCacheKey>(
347
335
 
348
336
  waitUntil(renderFullHTML());
349
337
 
350
- return {headers, body};
338
+ return body;
351
339
  }
352
340
  }
353
341
 
package/source/server.ts CHANGED
@@ -53,11 +53,4 @@ export type {
53
53
  } from '@quilted/react-server-render';
54
54
 
55
55
  export {ServerContext} from './server/ServerContext.tsx';
56
- export {
57
- renderToResponse,
58
- renderToFragmentResponse,
59
- } from './server/request-router.tsx';
60
- export {
61
- createAssetPreloader,
62
- type AssetPreloadOptions,
63
- } from './server/preload.ts';
56
+ export {renderToResponse} from './server/request-router.tsx';
package/tsconfig.json CHANGED
@@ -30,7 +30,6 @@
30
30
  {"path": "../request-router"},
31
31
  {"path": "../signals"},
32
32
  {"path": "../threads"},
33
- {"path": "../useful-react-types"},
34
33
  {"path": "../workers"}
35
34
  ]
36
35
  }
@@ -1,2 +0,0 @@
1
- export * from '@quilted/useful-react-types';
2
- export * from '@quilted/react-utilities';
@@ -1,35 +0,0 @@
1
- import { JSONResponse } from '@quilted/request-router';
2
-
3
- function createAssetPreloader(options) {
4
- return async function handler(request, requestContext) {
5
- const manifest = await assetsForRequest(request, {
6
- ...options,
7
- context: requestContext
8
- });
9
- return new JSONResponse(manifest);
10
- };
11
- }
12
- async function assetsForRequest(request, {
13
- assets,
14
- context,
15
- cacheKey: getCacheKey
16
- }) {
17
- const url = new URL(request.url);
18
- const modules = url.searchParams.get('modules')?.split(',') ?? [];
19
- const includeStyles = url.searchParams.get('styles') !== 'false';
20
- const includeScripts = url.searchParams.get('scripts') !== 'false';
21
- const cacheKey = (await getCacheKey?.(request, context)) ?? (await assets.cacheKey?.(request));
22
- const {
23
- styles,
24
- scripts
25
- } = await assets.entry({
26
- modules,
27
- cacheKey
28
- });
29
- const result = {};
30
- if (includeStyles) result.styles = styles;
31
- if (includeScripts) result.scripts = scripts;
32
- return result;
33
- }
34
-
35
- export { createAssetPreloader };
@@ -1,10 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
-
3
- function maybeWrapContext(Context, value, children) {
4
- return value ? /*#__PURE__*/jsx(Context.Provider, {
5
- value: value,
6
- children: children
7
- }) : children;
8
- }
9
-
10
- export { maybeWrapContext };
@@ -1,2 +0,0 @@
1
- export * from '@quilted/useful-react-types';
2
- export * from '@quilted/react-utilities';
@@ -1,34 +0,0 @@
1
- import { JSONResponse } from '@quilted/request-router';
2
-
3
- function createAssetPreloader(options) {
4
- return async function handler(request, requestContext) {
5
- const manifest = await assetsForRequest(request, {
6
- ...options,
7
- context: requestContext
8
- });
9
- return new JSONResponse(manifest);
10
- };
11
- }
12
- async function assetsForRequest(request, {
13
- assets,
14
- context,
15
- cacheKey: getCacheKey
16
- }) {
17
- const url = new URL(request.url);
18
- const modules = url.searchParams.get("modules")?.split(",") ?? [];
19
- const includeStyles = url.searchParams.get("styles") !== "false";
20
- const includeScripts = url.searchParams.get("scripts") !== "false";
21
- const cacheKey = await getCacheKey?.(request, context) ?? await assets.cacheKey?.(request);
22
- const { styles, scripts } = await assets.entry({
23
- modules,
24
- cacheKey
25
- });
26
- const result = {};
27
- if (includeStyles)
28
- result.styles = styles;
29
- if (includeScripts)
30
- result.scripts = scripts;
31
- return result;
32
- }
33
-
34
- export { createAssetPreloader };
@@ -1,7 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
-
3
- function maybeWrapContext(Context, value, children) {
4
- return value ? /* @__PURE__ */ jsx(Context.Provider, { value, children }) : children;
5
- }
6
-
7
- export { maybeWrapContext };
@@ -1,2 +0,0 @@
1
- export * from '@quilted/react/jsx-runtime';
2
- //# sourceMappingURL=jsx-runtime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsx-runtime.d.ts","sourceRoot":"","sources":["../../../source/react/jsx-runtime.ts"],"names":[],"mappings":"AACA,cAAc,4BAA4B,CAAC"}
@@ -1,3 +0,0 @@
1
- export * from '@quilted/useful-react-types';
2
- export * from '@quilted/react-utilities';
3
- //# sourceMappingURL=tools.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../source/react/tools.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from '@quilted/react-dom/server';
2
- //# sourceMappingURL=server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../source/react-dom/server.ts"],"names":[],"mappings":"AACA,cAAc,2BAA2B,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from '@quilted/react-dom/test-utils';
2
- //# sourceMappingURL=test-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../../source/react-dom/test-utils.ts"],"names":[],"mappings":"AACA,cAAc,+BAA+B,CAAC"}
@@ -1,3 +0,0 @@
1
- export * from '@quilted/react-dom';
2
- export { default } from '@quilted/react-dom';
3
- //# sourceMappingURL=react-dom.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react-dom.d.ts","sourceRoot":"","sources":["../../source/react-dom.ts"],"names":[],"mappings":"AACA,cAAc,oBAAoB,CAAC;AAEnC,OAAO,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from '@quilted/request-router';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/request-router/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
@@ -1,8 +0,0 @@
1
- import type { AssetsCacheKey, BrowserAssets } from '@quilted/assets';
2
- import { type EnhancedRequest, type RequestHandler, type RequestContext } from '@quilted/request-router';
3
- export interface AssetPreloadOptions<Context = RequestContext, CacheKey = AssetsCacheKey> {
4
- readonly assets: BrowserAssets<CacheKey>;
5
- cacheKey?(request: EnhancedRequest, context: Context): CacheKey | Promise<CacheKey>;
6
- }
7
- export declare function createAssetPreloader<Context = RequestContext, CacheKey = AssetsCacheKey>(options: AssetPreloadOptions<Context, CacheKey>): RequestHandler<Context>;
8
- //# sourceMappingURL=preload.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"preload.d.ts","sourceRoot":"","sources":["../../../source/server/preload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EAEd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,mBAAmB,CAClC,OAAO,GAAG,cAAc,EACxB,QAAQ,GAAG,cAAc;IAEzB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IACzC,QAAQ,CAAC,CACP,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,OAAO,GACf,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACjC;AAED,wBAAgB,oBAAoB,CAClC,OAAO,GAAG,cAAc,EACxB,QAAQ,GAAG,cAAc,EACzB,OAAO,EAAE,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,cAAc,CAAC,OAAO,CAAC,CAS1E"}
@@ -1,3 +0,0 @@
1
- import type { Context as ReactContext, ReactNode, ReactElement } from 'react';
2
- export declare function maybeWrapContext<T>(Context: ReactContext<T>, value: T | null | undefined, children: ReactNode): ReactElement;
3
- //# sourceMappingURL=react.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../source/utilities/react.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,IAAI,YAAY,EAAE,SAAS,EAAE,YAAY,EAAC,MAAM,OAAO,CAAC;AAE5E,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EACxB,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAC3B,QAAQ,EAAE,SAAS,GAClB,YAAY,CAMd"}
@@ -1,2 +0,0 @@
1
- // @ts-expect-error not used for types
2
- export * from '@quilted/react/jsx-runtime';
@@ -1,2 +0,0 @@
1
- export * from '@quilted/useful-react-types';
2
- export * from '@quilted/react-utilities';
@@ -1,2 +0,0 @@
1
- // @ts-expect-error not used for types
2
- export * from '@quilted/react-dom/server';
@@ -1,2 +0,0 @@
1
- // @ts-expect-error not used for types
2
- export * from '@quilted/react-dom/test-utils';
@@ -1,4 +0,0 @@
1
- // @ts-expect-error not used for types
2
- export * from '@quilted/react-dom';
3
- // @ts-expect-error not used for types
4
- export {default} from '@quilted/react-dom';