@react-aria/ssr 3.4.2-nightly.3698 → 3.4.2-nightly.3705

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 (2) hide show
  1. package/dist/import.mjs +117 -0
  2. package/package.json +7 -2
@@ -0,0 +1,117 @@
1
+ import $89yE2$react, {useContext as $89yE2$useContext, useMemo as $89yE2$useMemo, useRef as $89yE2$useRef, useState as $89yE2$useState, useLayoutEffect as $89yE2$useLayoutEffect} from "react";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */ /*
14
+ * Copyright 2020 Adobe. All rights reserved.
15
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License. You may obtain a copy
17
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software distributed under
20
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
+ * OF ANY KIND, either express or implied. See the License for the specific language
22
+ * governing permissions and limitations under the License.
23
+ */ // We must avoid a circular dependency with @react-aria/utils, and this useLayoutEffect is
24
+ // guarded by a check that it only runs on the client side.
25
+ // eslint-disable-next-line rulesdir/useLayoutEffectRule
26
+
27
+ // Default context value to use in case there is no SSRProvider. This is fine for
28
+ // client-only apps. In order to support multiple copies of React Aria potentially
29
+ // being on the page at once, the prefix is set to a random number. SSRProvider
30
+ // will reset this to zero for consistency between server and client, so in the
31
+ // SSR case multiple copies of React Aria is not supported.
32
+ const $704cf1d3b684cc5c$var$defaultContext = {
33
+ prefix: String(Math.round(Math.random() * 10000000000)),
34
+ current: 0
35
+ };
36
+ const $704cf1d3b684cc5c$var$SSRContext = /*#__PURE__*/ (0, $89yE2$react).createContext($704cf1d3b684cc5c$var$defaultContext);
37
+ function $704cf1d3b684cc5c$export$9f8ac96af4b1b2ae(props) {
38
+ let cur = (0, $89yE2$useContext)($704cf1d3b684cc5c$var$SSRContext);
39
+ let counter = $704cf1d3b684cc5c$var$useCounter(cur === $704cf1d3b684cc5c$var$defaultContext);
40
+ let value = (0, $89yE2$useMemo)(()=>({
41
+ // If this is the first SSRProvider, start with an empty string prefix, otherwise
42
+ // append and increment the counter.
43
+ prefix: cur === $704cf1d3b684cc5c$var$defaultContext ? "" : `${cur.prefix}-${counter}`,
44
+ current: 0
45
+ }), [
46
+ cur,
47
+ counter
48
+ ]);
49
+ return /*#__PURE__*/ (0, $89yE2$react).createElement($704cf1d3b684cc5c$var$SSRContext.Provider, {
50
+ value: value
51
+ }, props.children);
52
+ }
53
+ let $704cf1d3b684cc5c$var$canUseDOM = Boolean(typeof window !== "undefined" && window.document && window.document.createElement);
54
+ let $704cf1d3b684cc5c$var$componentIds = new WeakMap();
55
+ function $704cf1d3b684cc5c$var$useCounter(isDisabled = false) {
56
+ let ctx = (0, $89yE2$useContext)($704cf1d3b684cc5c$var$SSRContext);
57
+ let ref = (0, $89yE2$useRef)(null);
58
+ if (ref.current === null && !isDisabled) {
59
+ var _React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, _React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_ReactCurrentOwner;
60
+ // In strict mode, React renders components twice, and the ref will be reset to null on the second render.
61
+ // This means our id counter will be incremented twice instead of once. This is a problem because on the
62
+ // server, components are only rendered once and so ids generated on the server won't match the client.
63
+ // In React 18, useId was introduced to solve this, but it is not available in older versions. So to solve this
64
+ // we need to use some React internals to access the underlying Fiber instance, which is stable between renders.
65
+ // This is exposed as ReactCurrentOwner in development, which is all we need since StrictMode only runs in development.
66
+ // To ensure that we only increment the global counter once, we store the starting id for this component in
67
+ // a weak map associated with the Fiber. On the second render, we reset the global counter to this value.
68
+ // Since React runs the second render immediately after the first, this is safe.
69
+ // @ts-ignore
70
+ let currentOwner = (_React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = (0, $89yE2$react).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED === void 0 ? void 0 : (_React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_ReactCurrentOwner = _React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner) === null || _React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_ReactCurrentOwner === void 0 ? void 0 : _React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_ReactCurrentOwner.current;
71
+ if (currentOwner) {
72
+ let prevComponentValue = $704cf1d3b684cc5c$var$componentIds.get(currentOwner);
73
+ if (prevComponentValue == null) // On the first render, and first call to useId, store the id and state in our weak map.
74
+ $704cf1d3b684cc5c$var$componentIds.set(currentOwner, {
75
+ id: ctx.current,
76
+ state: currentOwner.memoizedState
77
+ });
78
+ else if (currentOwner.memoizedState !== prevComponentValue.state) {
79
+ // On the second render, the memoizedState gets reset by React.
80
+ // Reset the counter, and remove from the weak map so we don't
81
+ // do this for subsequent useId calls.
82
+ ctx.current = prevComponentValue.id;
83
+ $704cf1d3b684cc5c$var$componentIds.delete(currentOwner);
84
+ }
85
+ }
86
+ ref.current = ++ctx.current;
87
+ }
88
+ return ref.current;
89
+ }
90
+ function $704cf1d3b684cc5c$export$619500959fc48b26(defaultId) {
91
+ let ctx = (0, $89yE2$useContext)($704cf1d3b684cc5c$var$SSRContext);
92
+ // If we are rendering in a non-DOM environment, and there's no SSRProvider,
93
+ // provide a warning to hint to the developer to add one.
94
+ if (ctx === $704cf1d3b684cc5c$var$defaultContext && !$704cf1d3b684cc5c$var$canUseDOM) console.warn("When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.");
95
+ let counter = $704cf1d3b684cc5c$var$useCounter(!!defaultId);
96
+ return defaultId || `react-aria${ctx.prefix}-${counter}`;
97
+ }
98
+ function $704cf1d3b684cc5c$export$535bd6ca7f90a273() {
99
+ let cur = (0, $89yE2$useContext)($704cf1d3b684cc5c$var$SSRContext);
100
+ let isInSSRContext = cur !== $704cf1d3b684cc5c$var$defaultContext;
101
+ let [isSSR, setIsSSR] = (0, $89yE2$useState)(isInSSRContext);
102
+ // If on the client, and the component was initially server rendered,
103
+ // then schedule a layout effect to update the component after hydration.
104
+ if (typeof window !== "undefined" && isInSSRContext) // This if statement technically breaks the rules of hooks, but is safe
105
+ // because the condition never changes after mounting.
106
+ // eslint-disable-next-line react-hooks/rules-of-hooks
107
+ (0, $89yE2$useLayoutEffect)(()=>{
108
+ setIsSSR(false);
109
+ }, []);
110
+ return isSSR;
111
+ }
112
+
113
+
114
+
115
+
116
+ export {$704cf1d3b684cc5c$export$9f8ac96af4b1b2ae as SSRProvider, $704cf1d3b684cc5c$export$619500959fc48b26 as useSSRSafeId, $704cf1d3b684cc5c$export$535bd6ca7f90a273 as useIsSSR};
117
+ //# sourceMappingURL=module.js.map
package/package.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "@react-aria/ssr",
3
- "version": "3.4.2-nightly.3698+72ee92f6d",
3
+ "version": "3.4.2-nightly.3705+93b3c951e",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
+ "exports": {
9
+ "types": "./dist/types.d.ts",
10
+ "import": "./dist/import.mjs",
11
+ "require": "./dist/main.js"
12
+ },
8
13
  "types": "dist/types.d.ts",
9
14
  "source": "src/index.ts",
10
15
  "files": [
@@ -25,5 +30,5 @@
25
30
  "publishConfig": {
26
31
  "access": "public"
27
32
  },
28
- "gitHead": "72ee92f6d497163468a80642ccb96576f822f365"
33
+ "gitHead": "93b3c951eb784b14183f9988f2d188b34de8f42d"
29
34
  }