@parcel/rsc 2.16.5-canary.3498 → 3.0.0-alpha.0

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/rsc",
3
- "version": "2.16.5-canary.3498+59484858a",
3
+ "version": "3.0.0-alpha.0",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,6 +14,7 @@
14
14
  "url": "https://github.com/parcel-bundler/parcel.git"
15
15
  },
16
16
  "sideEffects": false,
17
+ "files": ["lib", "src"],
17
18
  "exports": {
18
19
  ".": {
19
20
  "types": "./src/ssg.d.ts"
@@ -29,6 +30,14 @@
29
30
  "./node": {
30
31
  "types": "./lib/node.d.ts",
31
32
  "default": "./src/node.tsx"
33
+ },
34
+ "./runtime/server": {
35
+ "source": "./src/runtime-server.js",
36
+ "default": "./src/runtime-server.js"
37
+ },
38
+ "./runtime/client": {
39
+ "source": "./src/runtime-client.js",
40
+ "default": "./src/runtime-client.js"
32
41
  }
33
42
  },
34
43
  "dependencies": {
@@ -43,6 +52,5 @@
43
52
  "peerDependencies": {
44
53
  "react": "^19.1.0",
45
54
  "react-dom": "^19.1.0"
46
- },
47
- "gitHead": "59484858a1a0bcbb71f74088956bb437a2db6505"
55
+ }
48
56
  }
@@ -0,0 +1,12 @@
1
+ 'use parcel-rsc-runtime';
2
+
3
+ export {createServerReference} from 'react-server-dom-parcel/client';
4
+ export {preinit} from 'react-dom';
5
+ export {
6
+ createResourcesProxy,
7
+ modulePreloadResource,
8
+ scriptPreloadResource,
9
+ stylesheetResource,
10
+ waitForCSS,
11
+ wrapClientReferenceWithResources,
12
+ } from './runtime-helpers';
@@ -0,0 +1,139 @@
1
+ /* eslint-env browser */
2
+ /* eslint-disable react/display-name */
3
+
4
+ 'use parcel-rsc-runtime';
5
+
6
+ import {createElement, Fragment} from 'react';
7
+
8
+ export function stylesheetResource(href) {
9
+ return createElement('link', {
10
+ rel: 'stylesheet',
11
+ href,
12
+ precedence: 'default',
13
+ });
14
+ }
15
+
16
+ export function modulePreloadResource(href) {
17
+ return createElement('link', {rel: 'modulepreload', href});
18
+ }
19
+
20
+ export function scriptPreloadResource(href) {
21
+ return createElement('link', {rel: 'preload', as: 'script', href});
22
+ }
23
+
24
+ export function wrapClientReferenceWithResources(Reference, resources) {
25
+ return props =>
26
+ createElement(Fragment, null, ...resources, createElement(Reference, props));
27
+ }
28
+
29
+ export function createResourcesProxy(
30
+ module,
31
+ esModule,
32
+ resources,
33
+ bootstrapScript,
34
+ ) {
35
+ if (typeof module === 'function') {
36
+ return createResourcesValueProxy(module, resources, bootstrapScript);
37
+ }
38
+
39
+ return new Proxy(module, {
40
+ get(target, prop, receiver) {
41
+ if (prop === '__esModule' && esModule) {
42
+ return true;
43
+ }
44
+ let value = Reflect.get(target, prop, receiver);
45
+ return createResourcesValueProxy(value, resources, bootstrapScript);
46
+ },
47
+ });
48
+ }
49
+
50
+ let cache = new WeakMap();
51
+ function createResourcesValueProxy(value, resources, bootstrapScript) {
52
+ if (typeof value === 'function') {
53
+ let cached = cache.get(value);
54
+ if (cached) {
55
+ return cached;
56
+ }
57
+
58
+ // Detect reads of `Component.prototype.isReactComponent` or `Component.$$typeof`
59
+ // prior to the function being called as an indication that this is a React component.
60
+ let isReactComponent = false;
61
+ let prototypeProxy;
62
+ if (typeof value.prototype === 'object') {
63
+ prototypeProxy = new Proxy(value.prototype, {
64
+ get(target, prop, receiver) {
65
+ if (prop === 'isReactComponent') {
66
+ isReactComponent = true;
67
+ }
68
+ return Reflect.get(target, prop, receiver);
69
+ },
70
+ });
71
+ }
72
+
73
+ let proxy = new Proxy(value, {
74
+ get(target, prop, receiver) {
75
+ if (
76
+ prototypeProxy &&
77
+ prop === 'prototype' &&
78
+ Object.getOwnPropertyDescriptor(target, 'prototype').configurable
79
+ ) {
80
+ return prototypeProxy;
81
+ }
82
+
83
+ if (prop === '$$typeof') {
84
+ isReactComponent = true;
85
+ }
86
+
87
+ if (bootstrapScript && prop === 'bootstrapScript') {
88
+ return bootstrapScript;
89
+ }
90
+
91
+ return Reflect.get(target, prop, receiver);
92
+ },
93
+ apply(target, thisArg, args) {
94
+ let result = Reflect.apply(target, thisArg, args);
95
+ return isReactComponent
96
+ ? createElement(Fragment, null, ...resources, result)
97
+ : result;
98
+ },
99
+ });
100
+
101
+ cache.set(value, proxy);
102
+ return proxy;
103
+ } else if (value && typeof value === 'object') {
104
+ let cached = cache.get(value);
105
+ if (cached) {
106
+ return cached;
107
+ }
108
+
109
+ let proxy = new Proxy(value, {
110
+ get(target, prop, receiver) {
111
+ let value = Reflect.get(target, prop, receiver);
112
+ return createResourcesValueProxy(value, resources, bootstrapScript);
113
+ },
114
+ });
115
+
116
+ cache.set(value, proxy);
117
+ return proxy;
118
+ }
119
+
120
+ return value;
121
+ }
122
+
123
+ export function waitForCSS(url) {
124
+ return new Promise((resolve, reject) => {
125
+ if (typeof document === 'undefined') {
126
+ return resolve();
127
+ }
128
+
129
+ let link = document.querySelector(
130
+ `link[rel="stylesheet"][href="${CSS.escape(url)}"]`,
131
+ );
132
+ if (!link || link.sheet) {
133
+ return resolve();
134
+ }
135
+
136
+ link.addEventListener('load', resolve);
137
+ link.addEventListener('error', reject);
138
+ });
139
+ }
@@ -0,0 +1,27 @@
1
+ 'use parcel-rsc-runtime';
2
+
3
+ export {
4
+ createClientReference,
5
+ registerServerReference,
6
+ registerServerActions,
7
+ } from 'react-server-dom-parcel/server.edge';
8
+ export {preinit} from 'react-dom';
9
+ export {
10
+ createResourcesProxy,
11
+ modulePreloadResource,
12
+ scriptPreloadResource,
13
+ stylesheetResource,
14
+ waitForCSS,
15
+ wrapClientReferenceWithResources,
16
+ } from './runtime-helpers';
17
+
18
+ export function ensureAsyncLocalStorage() {
19
+ if (typeof AsyncLocalStorage === 'undefined') {
20
+ try {
21
+ globalThis.AsyncLocalStorage =
22
+ require('node:async_hooks').AsyncLocalStorage;
23
+ } catch {
24
+ // The edge runtime may not provide node:async_hooks.
25
+ }
26
+ }
27
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2017-present Devon Govett
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/tsconfig.json DELETED
@@ -1,31 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig to read more about this file */
4
- "target": "ES2020",
5
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
- "jsx": "react-jsx",
7
- "useDefineForClassFields": true,
8
-
9
- /* Modules */
10
- "module": "ESNext",
11
- "moduleResolution": "bundler",
12
-
13
- /* Emit */
14
- "noEmit": true,
15
- "declaration": true,
16
-
17
- /* Interop Constraints */
18
- "isolatedModules": true,
19
- "isolatedDeclarations": true,
20
- "allowSyntheticDefaultImports": true,
21
- "allowImportingTsExtensions": true,
22
- "esModuleInterop": true,
23
- "forceConsistentCasingInFileNames": true,
24
-
25
- /* Type Checking */
26
- "strict": true,
27
-
28
- /* Completeness */
29
- "skipLibCheck": true
30
- }
31
- }
package/types.d.ts DELETED
@@ -1,81 +0,0 @@
1
- declare module 'react-server-dom-parcel/client' {
2
- type TemporaryReferenceSet = {__ref: true};
3
- type ReactCustomFormAction = {
4
- name?: string;
5
- action?: string;
6
- encType?: string;
7
- method?: string;
8
- target?: string;
9
- data?: null | FormData;
10
- };
11
- type EncodeFormActionCallback = <A>(
12
- id: any,
13
- args: Promise<A>,
14
- ) => ReactCustomFormAction;
15
- type Options = {
16
- nonce?: string;
17
- encodeFormAction?: EncodeFormActionCallback;
18
- temporaryReferences?: TemporaryReferenceSet;
19
- replayConsoleLogs?: boolean;
20
- environmentName?: string;
21
- };
22
-
23
- export function createFromFetch<T>(
24
- res: Promise<Response>,
25
- options?: Options,
26
- ): Promise<T>;
27
- export function createFromReadableStream<T>(
28
- stream: ReadableStream,
29
- options?: Options,
30
- ): Promise<T>;
31
- export function encodeReply(
32
- value: any,
33
- options?: {
34
- temporaryReferences?: TemporaryReferenceSet;
35
- signal?: AbortSignal | null | undefined;
36
- },
37
- ): Promise<string | URLSearchParams | FormData>;
38
- export function createTemporaryReferenceSet(): TemporaryReferenceSet;
39
-
40
- type CallServerCallback = <T>(id: string, args: any[]) => Promise<T>;
41
- export function setServerCallback(cb: CallServerCallback): void;
42
- }
43
-
44
- declare module 'react-server-dom-parcel/client.edge' {
45
- export function createFromReadableStream<T>(
46
- stream: ReadableStream,
47
- ): Promise<T>;
48
- }
49
-
50
- declare module 'react-server-dom-parcel/server.edge' {
51
- type TemporaryReferenceSet = {__ref: true};
52
- type Options = {
53
- environmentName?: string | (() => string);
54
- filterStackFrame?: (url: string, functionName: string) => boolean;
55
- identifierPrefix?: string;
56
- signal?: AbortSignal;
57
- temporaryReferences?: TemporaryReferenceSet;
58
- onError?: (error: unknown) => void;
59
- onPostpone?: (reason: string) => void;
60
- };
61
-
62
- export function renderToReadableStream(
63
- value: any,
64
- options?: Options,
65
- ): ReadableStream;
66
- export function loadServerAction(
67
- id: string,
68
- ): Promise<(...args: any[]) => Promise<any>>;
69
- export function decodeReply<T>(
70
- body: string | FormData,
71
- options?: {temporaryReferences?: TemporaryReferenceSet},
72
- ): Promise<T>;
73
- export function decodeAction(
74
- body: FormData,
75
- ): Promise<(...args: any[]) => Promise<any>>;
76
- export function createTemporaryReferenceSet(): TemporaryReferenceSet;
77
- }
78
-
79
- declare module 'react-dom/server.edge' {
80
- export * from 'react-dom/server';
81
- }