@react-aria/ssr 3.7.2-nightly.4088 → 3.7.2-nightly.4092
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/dist/import.mjs +8 -9
- package/dist/main.js +8 -9
- package/dist/main.js.map +1 -1
- package/dist/module.js +8 -9
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/SSRProvider.tsx +9 -10
package/dist/import.mjs
CHANGED
|
@@ -31,10 +31,10 @@ import $73SJx$react, {useContext as $73SJx$useContext, useState as $73SJx$useSta
|
|
|
31
31
|
// SSR case multiple copies of React Aria is not supported.
|
|
32
32
|
const $b5e257d569688ac6$var$defaultContext = {
|
|
33
33
|
prefix: String(Math.round(Math.random() * 10000000000)),
|
|
34
|
-
current: 0
|
|
35
|
-
isSSR: false
|
|
34
|
+
current: 0
|
|
36
35
|
};
|
|
37
36
|
const $b5e257d569688ac6$var$SSRContext = /*#__PURE__*/ (0, $73SJx$react).createContext($b5e257d569688ac6$var$defaultContext);
|
|
37
|
+
const $b5e257d569688ac6$var$IsSSRContext = /*#__PURE__*/ (0, $73SJx$react).createContext(false);
|
|
38
38
|
// This is only used in React < 18.
|
|
39
39
|
function $b5e257d569688ac6$var$LegacySSRProvider(props) {
|
|
40
40
|
let cur = (0, $73SJx$useContext)($b5e257d569688ac6$var$SSRContext);
|
|
@@ -44,12 +44,10 @@ function $b5e257d569688ac6$var$LegacySSRProvider(props) {
|
|
|
44
44
|
// If this is the first SSRProvider, start with an empty string prefix, otherwise
|
|
45
45
|
// append and increment the counter.
|
|
46
46
|
prefix: cur === $b5e257d569688ac6$var$defaultContext ? "" : `${cur.prefix}-${counter}`,
|
|
47
|
-
current: 0
|
|
48
|
-
isSSR: isSSR
|
|
47
|
+
current: 0
|
|
49
48
|
}), [
|
|
50
49
|
cur,
|
|
51
|
-
counter
|
|
52
|
-
isSSR
|
|
50
|
+
counter
|
|
53
51
|
]);
|
|
54
52
|
// If on the client, and the component was initially server rendered,
|
|
55
53
|
// then schedule a layout effect to update the component after hydration.
|
|
@@ -61,7 +59,9 @@ function $b5e257d569688ac6$var$LegacySSRProvider(props) {
|
|
|
61
59
|
}, []);
|
|
62
60
|
return /*#__PURE__*/ (0, $73SJx$react).createElement($b5e257d569688ac6$var$SSRContext.Provider, {
|
|
63
61
|
value: value
|
|
64
|
-
},
|
|
62
|
+
}, /*#__PURE__*/ (0, $73SJx$react).createElement($b5e257d569688ac6$var$IsSSRContext.Provider, {
|
|
63
|
+
value: isSSR
|
|
64
|
+
}, props.children));
|
|
65
65
|
}
|
|
66
66
|
let $b5e257d569688ac6$var$warnedAboutSSRProvider = false;
|
|
67
67
|
function $b5e257d569688ac6$export$9f8ac96af4b1b2ae(props) {
|
|
@@ -146,8 +146,7 @@ function $b5e257d569688ac6$export$535bd6ca7f90a273() {
|
|
|
146
146
|
// In React 18, we can use useSyncExternalStore to detect if we're server rendering or hydrating.
|
|
147
147
|
if (typeof (0, $73SJx$react)["useSyncExternalStore"] === "function") return (0, $73SJx$react)["useSyncExternalStore"]($b5e257d569688ac6$var$subscribe, $b5e257d569688ac6$var$getSnapshot, $b5e257d569688ac6$var$getServerSnapshot);
|
|
148
148
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
149
|
-
|
|
150
|
-
return cur.isSSR;
|
|
149
|
+
return (0, $73SJx$useContext)($b5e257d569688ac6$var$IsSSRContext);
|
|
151
150
|
}
|
|
152
151
|
|
|
153
152
|
|
package/dist/main.js
CHANGED
|
@@ -41,10 +41,10 @@ $parcel$export(module.exports, "useIsSSR", () => $97d95f6660b1bb14$export$535bd6
|
|
|
41
41
|
// SSR case multiple copies of React Aria is not supported.
|
|
42
42
|
const $97d95f6660b1bb14$var$defaultContext = {
|
|
43
43
|
prefix: String(Math.round(Math.random() * 10000000000)),
|
|
44
|
-
current: 0
|
|
45
|
-
isSSR: false
|
|
44
|
+
current: 0
|
|
46
45
|
};
|
|
47
46
|
const $97d95f6660b1bb14$var$SSRContext = /*#__PURE__*/ (0, ($parcel$interopDefault($32tCg$react))).createContext($97d95f6660b1bb14$var$defaultContext);
|
|
47
|
+
const $97d95f6660b1bb14$var$IsSSRContext = /*#__PURE__*/ (0, ($parcel$interopDefault($32tCg$react))).createContext(false);
|
|
48
48
|
// This is only used in React < 18.
|
|
49
49
|
function $97d95f6660b1bb14$var$LegacySSRProvider(props) {
|
|
50
50
|
let cur = (0, $32tCg$react.useContext)($97d95f6660b1bb14$var$SSRContext);
|
|
@@ -54,12 +54,10 @@ function $97d95f6660b1bb14$var$LegacySSRProvider(props) {
|
|
|
54
54
|
// If this is the first SSRProvider, start with an empty string prefix, otherwise
|
|
55
55
|
// append and increment the counter.
|
|
56
56
|
prefix: cur === $97d95f6660b1bb14$var$defaultContext ? "" : `${cur.prefix}-${counter}`,
|
|
57
|
-
current: 0
|
|
58
|
-
isSSR: isSSR
|
|
57
|
+
current: 0
|
|
59
58
|
}), [
|
|
60
59
|
cur,
|
|
61
|
-
counter
|
|
62
|
-
isSSR
|
|
60
|
+
counter
|
|
63
61
|
]);
|
|
64
62
|
// If on the client, and the component was initially server rendered,
|
|
65
63
|
// then schedule a layout effect to update the component after hydration.
|
|
@@ -71,7 +69,9 @@ function $97d95f6660b1bb14$var$LegacySSRProvider(props) {
|
|
|
71
69
|
}, []);
|
|
72
70
|
return /*#__PURE__*/ (0, ($parcel$interopDefault($32tCg$react))).createElement($97d95f6660b1bb14$var$SSRContext.Provider, {
|
|
73
71
|
value: value
|
|
74
|
-
},
|
|
72
|
+
}, /*#__PURE__*/ (0, ($parcel$interopDefault($32tCg$react))).createElement($97d95f6660b1bb14$var$IsSSRContext.Provider, {
|
|
73
|
+
value: isSSR
|
|
74
|
+
}, props.children));
|
|
75
75
|
}
|
|
76
76
|
let $97d95f6660b1bb14$var$warnedAboutSSRProvider = false;
|
|
77
77
|
function $97d95f6660b1bb14$export$9f8ac96af4b1b2ae(props) {
|
|
@@ -156,8 +156,7 @@ function $97d95f6660b1bb14$export$535bd6ca7f90a273() {
|
|
|
156
156
|
// In React 18, we can use useSyncExternalStore to detect if we're server rendering or hydrating.
|
|
157
157
|
if (typeof (0, ($parcel$interopDefault($32tCg$react)))["useSyncExternalStore"] === "function") return (0, ($parcel$interopDefault($32tCg$react)))["useSyncExternalStore"]($97d95f6660b1bb14$var$subscribe, $97d95f6660b1bb14$var$getSnapshot, $97d95f6660b1bb14$var$getServerSnapshot);
|
|
158
158
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
159
|
-
|
|
160
|
-
return cur.isSSR;
|
|
159
|
+
return (0, $32tCg$react.useContext)($97d95f6660b1bb14$var$IsSSRContext);
|
|
161
160
|
}
|
|
162
161
|
|
|
163
162
|
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED,0FAA0F;AAC1F,2DAA2D;AAC3D,wDAAwD;;AAexD,iFAAiF;AACjF,kFAAkF;AAClF,+EAA+E;AAC/E,+EAA+E;AAC/E,2DAA2D;AAC3D,MAAM,uCAAkC;IACtC,QAAQ,OAAO,KAAK,MAAM,KAAK,WAAW;IAC1C,SAAS;IACT,OAAO;AACT;AAEA,MAAM,iDAAa,CAAA,GAAA,sCAAI,EAAE,cAA+B;AAOxD,mCAAmC;AACnC,SAAS,wCAAkB,KAAuB;IAChD,IAAI,MAAM,CAAA,GAAA,uBAAS,EAAE;IACrB,IAAI,UAAU,iCAAW,QAAQ;IACjC,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,qBAAO,EAAE;IACjC,IAAI,QAAyB,CAAA,GAAA,oBAAM,EAAE,IAAO,CAAA;YAC1C,iFAAiF;YACjF,oCAAoC;YACpC,QAAQ,QAAQ,uCAAiB,KAAK,CAAC,EAAE,IAAI,OAAO,CAAC,EAAE,QAAQ,CAAC;YAChE,SAAS;mBACT;QACF,CAAA,GAAI;QA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AAuB,CAAC,iCAAW,mCAAa;IAG/D,sDAAsD;IACtD,IAAI,MAAM,CAAA,GAAA,uBAAS,EAAE;IACrB,OAAO,IAAI;AACb;;CD5LC","sources":["packages/@react-aria/ssr/src/index.ts","packages/@react-aria/ssr/src/SSRProvider.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {SSRProvider, useSSRSafeId, useIsSSR} from './SSRProvider';\nexport type {SSRProviderProps} from './SSRProvider';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// We must avoid a circular dependency with @react-aria/utils, and this useLayoutEffect is\n// guarded by a check that it only runs on the client side.\n// eslint-disable-next-line rulesdir/useLayoutEffectRule\nimport React, {ReactNode, useContext, useLayoutEffect, useMemo, useRef, useState} from 'react';\n\n// To support SSR, the auto incrementing id counter is stored in a context. This allows\n// it to be reset on every request to ensure the client and server are consistent.\n// There is also a prefix string that is used to support async loading components\n// Each async boundary must be wrapped in an SSR provider, which appends to the prefix\n// and resets the current id counter. This ensures that async loaded components have\n// consistent ids regardless of the loading order.\ninterface SSRContextValue {\n prefix: string,\n current: number,\n isSSR: boolean\n}\n\n// Default context value to use in case there is no SSRProvider. This is fine for\n// client-only apps. In order to support multiple copies of React Aria potentially\n// being on the page at once, the prefix is set to a random number. SSRProvider\n// will reset this to zero for consistency between server and client, so in the\n// SSR case multiple copies of React Aria is not supported.\nconst defaultContext: SSRContextValue = {\n prefix: String(Math.round(Math.random() * 10000000000)),\n current: 0,\n isSSR: false\n};\n\nconst SSRContext = React.createContext<SSRContextValue>(defaultContext);\n\nexport interface SSRProviderProps {\n /** Your application here. */\n children: ReactNode\n}\n\n// This is only used in React < 18.\nfunction LegacySSRProvider(props: SSRProviderProps): JSX.Element {\n let cur = useContext(SSRContext);\n let counter = useCounter(cur === defaultContext);\n let [isSSR, setIsSSR] = useState(true);\n let value: SSRContextValue = useMemo(() => ({\n // If this is the first SSRProvider, start with an empty string prefix, otherwise\n // append and increment the counter.\n prefix: cur === defaultContext ? '' : `${cur.prefix}-${counter}`,\n current: 0,\n isSSR\n }), [cur, counter, isSSR]);\n\n // If on the client, and the component was initially server rendered,\n // then schedule a layout effect to update the component after hydration.\n if (typeof document !== 'undefined') {\n // This if statement technically breaks the rules of hooks, but is safe\n // because the condition never changes after mounting.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useLayoutEffect(() => {\n setIsSSR(false);\n }, []);\n }\n\n return (\n <SSRContext.Provider value={value}>\n {props.children}\n </SSRContext.Provider>\n );\n}\n\nlet warnedAboutSSRProvider = false;\n\n/**\n * When using SSR with React Aria in React 16 or 17, applications must be wrapped in an SSRProvider.\n * This ensures that auto generated ids are consistent between the client and server.\n */\nexport function SSRProvider(props: SSRProviderProps): JSX.Element {\n if (typeof React['useId'] === 'function') {\n if (process.env.NODE_ENV !== 'test' && !warnedAboutSSRProvider) {\n console.warn('In React 18, SSRProvider is not necessary and is a noop. You can remove it from your app.');\n warnedAboutSSRProvider = true;\n }\n return <>{props.children}</>;\n }\n return <LegacySSRProvider {...props} />;\n}\n\nlet canUseDOM = Boolean(\n typeof window !== 'undefined' &&\n window.document &&\n window.document.createElement\n);\n\nlet componentIds = new WeakMap();\n\nfunction useCounter(isDisabled = false) {\n let ctx = useContext(SSRContext);\n let ref = useRef<number | null>(null);\n // eslint-disable-next-line rulesdir/pure-render\n if (ref.current === null && !isDisabled) {\n // In strict mode, React renders components twice, and the ref will be reset to null on the second render.\n // This means our id counter will be incremented twice instead of once. This is a problem because on the\n // server, components are only rendered once and so ids generated on the server won't match the client.\n // In React 18, useId was introduced to solve this, but it is not available in older versions. So to solve this\n // we need to use some React internals to access the underlying Fiber instance, which is stable between renders.\n // This is exposed as ReactCurrentOwner in development, which is all we need since StrictMode only runs in development.\n // To ensure that we only increment the global counter once, we store the starting id for this component in\n // a weak map associated with the Fiber. On the second render, we reset the global counter to this value.\n // Since React runs the second render immediately after the first, this is safe.\n // @ts-ignore\n let currentOwner = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?.ReactCurrentOwner?.current;\n if (currentOwner) {\n let prevComponentValue = componentIds.get(currentOwner);\n if (prevComponentValue == null) {\n // On the first render, and first call to useId, store the id and state in our weak map.\n componentIds.set(currentOwner, {\n id: ctx.current,\n state: currentOwner.memoizedState\n });\n } else if (currentOwner.memoizedState !== prevComponentValue.state) {\n // On the second render, the memoizedState gets reset by React.\n // Reset the counter, and remove from the weak map so we don't\n // do this for subsequent useId calls.\n ctx.current = prevComponentValue.id;\n componentIds.delete(currentOwner);\n }\n }\n\n // eslint-disable-next-line rulesdir/pure-render\n ref.current = ++ctx.current;\n }\n\n // eslint-disable-next-line rulesdir/pure-render\n return ref.current;\n}\n\nfunction useLegacySSRSafeId(defaultId?: string): string {\n let ctx = useContext(SSRContext);\n\n // If we are rendering in a non-DOM environment, and there's no SSRProvider,\n // provide a warning to hint to the developer to add one.\n if (ctx === defaultContext && !canUseDOM) {\n console.warn('When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.');\n }\n\n let counter = useCounter(!!defaultId);\n let prefix = ctx === defaultContext && process.env.NODE_ENV === 'test' ? 'react-aria' : `react-aria${ctx.prefix}`;\n return defaultId || `${prefix}-${counter}`;\n}\n\nfunction useModernSSRSafeId(defaultId?: string): string {\n // @ts-ignore\n let id = React.useId();\n let [didSSR] = useState(useIsSSR());\n let prefix = didSSR || process.env.NODE_ENV === 'test' ? 'react-aria' : `react-aria${defaultContext.prefix}`;\n return defaultId || `${prefix}-${id}`;\n}\n\n// Use React.useId in React 18 if available, otherwise fall back to our old implementation.\n/** @private */\nexport const useSSRSafeId = typeof React['useId'] === 'function' ? useModernSSRSafeId : useLegacySSRSafeId;\n\nfunction getSnapshot() {\n return false;\n}\n\nfunction getServerSnapshot() {\n return true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction subscribe(onStoreChange: () => void): () => void {\n // noop\n return () => {};\n}\n\n/**\n * Returns whether the component is currently being server side rendered or\n * hydrated on the client. Can be used to delay browser-specific rendering\n * until after hydration.\n */\nexport function useIsSSR(): boolean {\n // In React 18, we can use useSyncExternalStore to detect if we're server rendering or hydrating.\n if (typeof React['useSyncExternalStore'] === 'function') {\n return React['useSyncExternalStore'](subscribe, getSnapshot, getServerSnapshot);\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n let cur = useContext(SSRContext);\n return cur.isSSR;\n}\n"],"names":[],"version":3,"file":"main.js.map","sourceRoot":"../../../../"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED,0FAA0F;AAC1F,2DAA2D;AAC3D,wDAAwD;;AAcxD,iFAAiF;AACjF,kFAAkF;AAClF,+EAA+E;AAC/E,+EAA+E;AAC/E,2DAA2D;AAC3D,MAAM,uCAAkC;IACtC,QAAQ,OAAO,KAAK,MAAM,KAAK,WAAW;IAC1C,SAAS;AACX;AAEA,MAAM,iDAAa,CAAA,GAAA,sCAAI,EAAE,cAA+B;AACxD,MAAM,mDAAe,CAAA,GAAA,sCAAI,EAAE,cAAc;AAOzC,mCAAmC;AACnC,SAAS,wCAAkB,KAAuB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AAG,CAAC;AACvC;AAIO,MAAM,4CAAe,OAAO,CAAA,GAAA,sCAAI,CAAC,CAAC,QAAQ,KAAK,aAAa,2CAAqB;AAExF,SAAS;IACP,OAAO;AACT;AAEA,SAAS;IACP,OAAO;AACT;AAEA,6DAA6D;AAC7D,SAAS,gCAAU,aAAyB;IAC1C,OAAO;IACP,OAAO,KAAO;AAChB;AAOO,SAAS;IACd,iGAAiG;IACjG,IAAI,OAAO,CAAA,GAAA,sCAAI,CAAC,CAAC,uBAAuB,KAAK,YAC3C,OAAO,CAAA,GAAA,sCAAI,CAAC,CAAC,uBAAuB,CAAC,iCAAW,mCAAa;IAG/D,sDAAsD;IACtD,OAAO,CAAA,GAAA,uBAAS,EAAE;AACpB;;CD3LC","sources":["packages/@react-aria/ssr/src/index.ts","packages/@react-aria/ssr/src/SSRProvider.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {SSRProvider, useSSRSafeId, useIsSSR} from './SSRProvider';\nexport type {SSRProviderProps} from './SSRProvider';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// We must avoid a circular dependency with @react-aria/utils, and this useLayoutEffect is\n// guarded by a check that it only runs on the client side.\n// eslint-disable-next-line rulesdir/useLayoutEffectRule\nimport React, {ReactNode, useContext, useLayoutEffect, useMemo, useRef, useState} from 'react';\n\n// To support SSR, the auto incrementing id counter is stored in a context. This allows\n// it to be reset on every request to ensure the client and server are consistent.\n// There is also a prefix string that is used to support async loading components\n// Each async boundary must be wrapped in an SSR provider, which appends to the prefix\n// and resets the current id counter. This ensures that async loaded components have\n// consistent ids regardless of the loading order.\ninterface SSRContextValue {\n prefix: string,\n current: number\n}\n\n// Default context value to use in case there is no SSRProvider. This is fine for\n// client-only apps. In order to support multiple copies of React Aria potentially\n// being on the page at once, the prefix is set to a random number. SSRProvider\n// will reset this to zero for consistency between server and client, so in the\n// SSR case multiple copies of React Aria is not supported.\nconst defaultContext: SSRContextValue = {\n prefix: String(Math.round(Math.random() * 10000000000)),\n current: 0\n};\n\nconst SSRContext = React.createContext<SSRContextValue>(defaultContext);\nconst IsSSRContext = React.createContext(false);\n\nexport interface SSRProviderProps {\n /** Your application here. */\n children: ReactNode\n}\n\n// This is only used in React < 18.\nfunction LegacySSRProvider(props: SSRProviderProps): JSX.Element {\n let cur = useContext(SSRContext);\n let counter = useCounter(cur === defaultContext);\n let [isSSR, setIsSSR] = useState(true);\n let value: SSRContextValue = useMemo(() => ({\n // If this is the first SSRProvider, start with an empty string prefix, otherwise\n // append and increment the counter.\n prefix: cur === defaultContext ? '' : `${cur.prefix}-${counter}`,\n current: 0\n }), [cur, counter]);\n\n // If on the client, and the component was initially server rendered,\n // then schedule a layout effect to update the component after hydration.\n if (typeof document !== 'undefined') {\n // This if statement technically breaks the rules of hooks, but is safe\n // because the condition never changes after mounting.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useLayoutEffect(() => {\n setIsSSR(false);\n }, []);\n }\n\n return (\n <SSRContext.Provider value={value}>\n <IsSSRContext.Provider value={isSSR}>\n {props.children}\n </IsSSRContext.Provider>\n </SSRContext.Provider>\n );\n}\n\nlet warnedAboutSSRProvider = false;\n\n/**\n * When using SSR with React Aria in React 16 or 17, applications must be wrapped in an SSRProvider.\n * This ensures that auto generated ids are consistent between the client and server.\n */\nexport function SSRProvider(props: SSRProviderProps): JSX.Element {\n if (typeof React['useId'] === 'function') {\n if (process.env.NODE_ENV !== 'test' && !warnedAboutSSRProvider) {\n console.warn('In React 18, SSRProvider is not necessary and is a noop. You can remove it from your app.');\n warnedAboutSSRProvider = true;\n }\n return <>{props.children}</>;\n }\n return <LegacySSRProvider {...props} />;\n}\n\nlet canUseDOM = Boolean(\n typeof window !== 'undefined' &&\n window.document &&\n window.document.createElement\n);\n\nlet componentIds = new WeakMap();\n\nfunction useCounter(isDisabled = false) {\n let ctx = useContext(SSRContext);\n let ref = useRef<number | null>(null);\n // eslint-disable-next-line rulesdir/pure-render\n if (ref.current === null && !isDisabled) {\n // In strict mode, React renders components twice, and the ref will be reset to null on the second render.\n // This means our id counter will be incremented twice instead of once. This is a problem because on the\n // server, components are only rendered once and so ids generated on the server won't match the client.\n // In React 18, useId was introduced to solve this, but it is not available in older versions. So to solve this\n // we need to use some React internals to access the underlying Fiber instance, which is stable between renders.\n // This is exposed as ReactCurrentOwner in development, which is all we need since StrictMode only runs in development.\n // To ensure that we only increment the global counter once, we store the starting id for this component in\n // a weak map associated with the Fiber. On the second render, we reset the global counter to this value.\n // Since React runs the second render immediately after the first, this is safe.\n // @ts-ignore\n let currentOwner = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?.ReactCurrentOwner?.current;\n if (currentOwner) {\n let prevComponentValue = componentIds.get(currentOwner);\n if (prevComponentValue == null) {\n // On the first render, and first call to useId, store the id and state in our weak map.\n componentIds.set(currentOwner, {\n id: ctx.current,\n state: currentOwner.memoizedState\n });\n } else if (currentOwner.memoizedState !== prevComponentValue.state) {\n // On the second render, the memoizedState gets reset by React.\n // Reset the counter, and remove from the weak map so we don't\n // do this for subsequent useId calls.\n ctx.current = prevComponentValue.id;\n componentIds.delete(currentOwner);\n }\n }\n\n // eslint-disable-next-line rulesdir/pure-render\n ref.current = ++ctx.current;\n }\n\n // eslint-disable-next-line rulesdir/pure-render\n return ref.current;\n}\n\nfunction useLegacySSRSafeId(defaultId?: string): string {\n let ctx = useContext(SSRContext);\n\n // If we are rendering in a non-DOM environment, and there's no SSRProvider,\n // provide a warning to hint to the developer to add one.\n if (ctx === defaultContext && !canUseDOM) {\n console.warn('When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.');\n }\n\n let counter = useCounter(!!defaultId);\n let prefix = ctx === defaultContext && process.env.NODE_ENV === 'test' ? 'react-aria' : `react-aria${ctx.prefix}`;\n return defaultId || `${prefix}-${counter}`;\n}\n\nfunction useModernSSRSafeId(defaultId?: string): string {\n // @ts-ignore\n let id = React.useId();\n let [didSSR] = useState(useIsSSR());\n let prefix = didSSR || process.env.NODE_ENV === 'test' ? 'react-aria' : `react-aria${defaultContext.prefix}`;\n return defaultId || `${prefix}-${id}`;\n}\n\n// Use React.useId in React 18 if available, otherwise fall back to our old implementation.\n/** @private */\nexport const useSSRSafeId = typeof React['useId'] === 'function' ? useModernSSRSafeId : useLegacySSRSafeId;\n\nfunction getSnapshot() {\n return false;\n}\n\nfunction getServerSnapshot() {\n return true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction subscribe(onStoreChange: () => void): () => void {\n // noop\n return () => {};\n}\n\n/**\n * Returns whether the component is currently being server side rendered or\n * hydrated on the client. Can be used to delay browser-specific rendering\n * until after hydration.\n */\nexport function useIsSSR(): boolean {\n // In React 18, we can use useSyncExternalStore to detect if we're server rendering or hydrating.\n if (typeof React['useSyncExternalStore'] === 'function') {\n return React['useSyncExternalStore'](subscribe, getSnapshot, getServerSnapshot);\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useContext(IsSSRContext);\n}\n"],"names":[],"version":3,"file":"main.js.map","sourceRoot":"../../../../"}
|
package/dist/module.js
CHANGED
|
@@ -31,10 +31,10 @@ import $73SJx$react, {useContext as $73SJx$useContext, useState as $73SJx$useSta
|
|
|
31
31
|
// SSR case multiple copies of React Aria is not supported.
|
|
32
32
|
const $b5e257d569688ac6$var$defaultContext = {
|
|
33
33
|
prefix: String(Math.round(Math.random() * 10000000000)),
|
|
34
|
-
current: 0
|
|
35
|
-
isSSR: false
|
|
34
|
+
current: 0
|
|
36
35
|
};
|
|
37
36
|
const $b5e257d569688ac6$var$SSRContext = /*#__PURE__*/ (0, $73SJx$react).createContext($b5e257d569688ac6$var$defaultContext);
|
|
37
|
+
const $b5e257d569688ac6$var$IsSSRContext = /*#__PURE__*/ (0, $73SJx$react).createContext(false);
|
|
38
38
|
// This is only used in React < 18.
|
|
39
39
|
function $b5e257d569688ac6$var$LegacySSRProvider(props) {
|
|
40
40
|
let cur = (0, $73SJx$useContext)($b5e257d569688ac6$var$SSRContext);
|
|
@@ -44,12 +44,10 @@ function $b5e257d569688ac6$var$LegacySSRProvider(props) {
|
|
|
44
44
|
// If this is the first SSRProvider, start with an empty string prefix, otherwise
|
|
45
45
|
// append and increment the counter.
|
|
46
46
|
prefix: cur === $b5e257d569688ac6$var$defaultContext ? "" : `${cur.prefix}-${counter}`,
|
|
47
|
-
current: 0
|
|
48
|
-
isSSR: isSSR
|
|
47
|
+
current: 0
|
|
49
48
|
}), [
|
|
50
49
|
cur,
|
|
51
|
-
counter
|
|
52
|
-
isSSR
|
|
50
|
+
counter
|
|
53
51
|
]);
|
|
54
52
|
// If on the client, and the component was initially server rendered,
|
|
55
53
|
// then schedule a layout effect to update the component after hydration.
|
|
@@ -61,7 +59,9 @@ function $b5e257d569688ac6$var$LegacySSRProvider(props) {
|
|
|
61
59
|
}, []);
|
|
62
60
|
return /*#__PURE__*/ (0, $73SJx$react).createElement($b5e257d569688ac6$var$SSRContext.Provider, {
|
|
63
61
|
value: value
|
|
64
|
-
},
|
|
62
|
+
}, /*#__PURE__*/ (0, $73SJx$react).createElement($b5e257d569688ac6$var$IsSSRContext.Provider, {
|
|
63
|
+
value: isSSR
|
|
64
|
+
}, props.children));
|
|
65
65
|
}
|
|
66
66
|
let $b5e257d569688ac6$var$warnedAboutSSRProvider = false;
|
|
67
67
|
function $b5e257d569688ac6$export$9f8ac96af4b1b2ae(props) {
|
|
@@ -146,8 +146,7 @@ function $b5e257d569688ac6$export$535bd6ca7f90a273() {
|
|
|
146
146
|
// In React 18, we can use useSyncExternalStore to detect if we're server rendering or hydrating.
|
|
147
147
|
if (typeof (0, $73SJx$react)["useSyncExternalStore"] === "function") return (0, $73SJx$react)["useSyncExternalStore"]($b5e257d569688ac6$var$subscribe, $b5e257d569688ac6$var$getSnapshot, $b5e257d569688ac6$var$getServerSnapshot);
|
|
148
148
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
149
|
-
|
|
150
|
-
return cur.isSSR;
|
|
149
|
+
return (0, $73SJx$useContext)($b5e257d569688ac6$var$IsSSRContext);
|
|
151
150
|
}
|
|
152
151
|
|
|
153
152
|
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED,0FAA0F;AAC1F,2DAA2D;AAC3D,wDAAwD;;AAexD,iFAAiF;AACjF,kFAAkF;AAClF,+EAA+E;AAC/E,+EAA+E;AAC/E,2DAA2D;AAC3D,MAAM,uCAAkC;IACtC,QAAQ,OAAO,KAAK,MAAM,KAAK,WAAW;IAC1C,SAAS;IACT,OAAO;AACT;AAEA,MAAM,iDAAa,CAAA,GAAA,YAAI,EAAE,cAA+B;AAOxD,mCAAmC;AACnC,SAAS,wCAAkB,KAAuB;IAChD,IAAI,MAAM,CAAA,GAAA,iBAAS,EAAE;IACrB,IAAI,UAAU,iCAAW,QAAQ;IACjC,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,eAAO,EAAE;IACjC,IAAI,QAAyB,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA;YAC1C,iFAAiF;YACjF,oCAAoC;YACpC,QAAQ,QA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OAAO,CAAA,GAAA,YAAI,CAAC,CAAC,uBAAuB,KAAK,YAC3C,OAAO,CAAA,GAAA,YAAI,CAAC,CAAC,uBAAuB,CAAC,iCAAW,mCAAa;IAG/D,sDAAsD;IACtD,IAAI,MAAM,CAAA,GAAA,iBAAS,EAAE;IACrB,OAAO,IAAI;AACb;;CD5LC","sources":["packages/@react-aria/ssr/src/index.ts","packages/@react-aria/ssr/src/SSRProvider.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {SSRProvider, useSSRSafeId, useIsSSR} from './SSRProvider';\nexport type {SSRProviderProps} from './SSRProvider';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// We must avoid a circular dependency with @react-aria/utils, and this useLayoutEffect is\n// guarded by a check that it only runs on the client side.\n// eslint-disable-next-line rulesdir/useLayoutEffectRule\nimport React, {ReactNode, useContext, useLayoutEffect, useMemo, useRef, useState} from 'react';\n\n// To support SSR, the auto incrementing id counter is stored in a context. This allows\n// it to be reset on every request to ensure the client and server are consistent.\n// There is also a prefix string that is used to support async loading components\n// Each async boundary must be wrapped in an SSR provider, which appends to the prefix\n// and resets the current id counter. This ensures that async loaded components have\n// consistent ids regardless of the loading order.\ninterface SSRContextValue {\n prefix: string,\n current: number,\n isSSR: boolean\n}\n\n// Default context value to use in case there is no SSRProvider. This is fine for\n// client-only apps. In order to support multiple copies of React Aria potentially\n// being on the page at once, the prefix is set to a random number. SSRProvider\n// will reset this to zero for consistency between server and client, so in the\n// SSR case multiple copies of React Aria is not supported.\nconst defaultContext: SSRContextValue = {\n prefix: String(Math.round(Math.random() * 10000000000)),\n current: 0,\n isSSR: false\n};\n\nconst SSRContext = React.createContext<SSRContextValue>(defaultContext);\n\nexport interface SSRProviderProps {\n /** Your application here. */\n children: ReactNode\n}\n\n// This is only used in React < 18.\nfunction LegacySSRProvider(props: SSRProviderProps): JSX.Element {\n let cur = useContext(SSRContext);\n let counter = useCounter(cur === defaultContext);\n let [isSSR, setIsSSR] = useState(true);\n let value: SSRContextValue = useMemo(() => ({\n // If this is the first SSRProvider, start with an empty string prefix, otherwise\n // append and increment the counter.\n prefix: cur === defaultContext ? '' : `${cur.prefix}-${counter}`,\n current: 0,\n isSSR\n }), [cur, counter, isSSR]);\n\n // If on the client, and the component was initially server rendered,\n // then schedule a layout effect to update the component after hydration.\n if (typeof document !== 'undefined') {\n // This if statement technically breaks the rules of hooks, but is safe\n // because the condition never changes after mounting.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useLayoutEffect(() => {\n setIsSSR(false);\n }, []);\n }\n\n return (\n <SSRContext.Provider value={value}>\n {props.children}\n </SSRContext.Provider>\n );\n}\n\nlet warnedAboutSSRProvider = false;\n\n/**\n * When using SSR with React Aria in React 16 or 17, applications must be wrapped in an SSRProvider.\n * This ensures that auto generated ids are consistent between the client and server.\n */\nexport function SSRProvider(props: SSRProviderProps): JSX.Element {\n if (typeof React['useId'] === 'function') {\n if (process.env.NODE_ENV !== 'test' && !warnedAboutSSRProvider) {\n console.warn('In React 18, SSRProvider is not necessary and is a noop. You can remove it from your app.');\n warnedAboutSSRProvider = true;\n }\n return <>{props.children}</>;\n }\n return <LegacySSRProvider {...props} />;\n}\n\nlet canUseDOM = Boolean(\n typeof window !== 'undefined' &&\n window.document &&\n window.document.createElement\n);\n\nlet componentIds = new WeakMap();\n\nfunction useCounter(isDisabled = false) {\n let ctx = useContext(SSRContext);\n let ref = useRef<number | null>(null);\n // eslint-disable-next-line rulesdir/pure-render\n if (ref.current === null && !isDisabled) {\n // In strict mode, React renders components twice, and the ref will be reset to null on the second render.\n // This means our id counter will be incremented twice instead of once. This is a problem because on the\n // server, components are only rendered once and so ids generated on the server won't match the client.\n // In React 18, useId was introduced to solve this, but it is not available in older versions. So to solve this\n // we need to use some React internals to access the underlying Fiber instance, which is stable between renders.\n // This is exposed as ReactCurrentOwner in development, which is all we need since StrictMode only runs in development.\n // To ensure that we only increment the global counter once, we store the starting id for this component in\n // a weak map associated with the Fiber. On the second render, we reset the global counter to this value.\n // Since React runs the second render immediately after the first, this is safe.\n // @ts-ignore\n let currentOwner = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?.ReactCurrentOwner?.current;\n if (currentOwner) {\n let prevComponentValue = componentIds.get(currentOwner);\n if (prevComponentValue == null) {\n // On the first render, and first call to useId, store the id and state in our weak map.\n componentIds.set(currentOwner, {\n id: ctx.current,\n state: currentOwner.memoizedState\n });\n } else if (currentOwner.memoizedState !== prevComponentValue.state) {\n // On the second render, the memoizedState gets reset by React.\n // Reset the counter, and remove from the weak map so we don't\n // do this for subsequent useId calls.\n ctx.current = prevComponentValue.id;\n componentIds.delete(currentOwner);\n }\n }\n\n // eslint-disable-next-line rulesdir/pure-render\n ref.current = ++ctx.current;\n }\n\n // eslint-disable-next-line rulesdir/pure-render\n return ref.current;\n}\n\nfunction useLegacySSRSafeId(defaultId?: string): string {\n let ctx = useContext(SSRContext);\n\n // If we are rendering in a non-DOM environment, and there's no SSRProvider,\n // provide a warning to hint to the developer to add one.\n if (ctx === defaultContext && !canUseDOM) {\n console.warn('When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.');\n }\n\n let counter = useCounter(!!defaultId);\n let prefix = ctx === defaultContext && process.env.NODE_ENV === 'test' ? 'react-aria' : `react-aria${ctx.prefix}`;\n return defaultId || `${prefix}-${counter}`;\n}\n\nfunction useModernSSRSafeId(defaultId?: string): string {\n // @ts-ignore\n let id = React.useId();\n let [didSSR] = useState(useIsSSR());\n let prefix = didSSR || process.env.NODE_ENV === 'test' ? 'react-aria' : `react-aria${defaultContext.prefix}`;\n return defaultId || `${prefix}-${id}`;\n}\n\n// Use React.useId in React 18 if available, otherwise fall back to our old implementation.\n/** @private */\nexport const useSSRSafeId = typeof React['useId'] === 'function' ? useModernSSRSafeId : useLegacySSRSafeId;\n\nfunction getSnapshot() {\n return false;\n}\n\nfunction getServerSnapshot() {\n return true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction subscribe(onStoreChange: () => void): () => void {\n // noop\n return () => {};\n}\n\n/**\n * Returns whether the component is currently being server side rendered or\n * hydrated on the client. Can be used to delay browser-specific rendering\n * until after hydration.\n */\nexport function useIsSSR(): boolean {\n // In React 18, we can use useSyncExternalStore to detect if we're server rendering or hydrating.\n if (typeof React['useSyncExternalStore'] === 'function') {\n return React['useSyncExternalStore'](subscribe, getSnapshot, getServerSnapshot);\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n let cur = useContext(SSRContext);\n return cur.isSSR;\n}\n"],"names":[],"version":3,"file":"module.js.map","sourceRoot":"../../../../"}
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED,0FAA0F;AAC1F,2DAA2D;AAC3D,wDAAwD;;AAcxD,iFAAiF;AACjF,kFAAkF;AAClF,+EAA+E;AAC/E,+EAA+E;AAC/E,2DAA2D;AAC3D,MAAM,uCAAkC;IACtC,QAAQ,OAAO,KAAK,MAAM,KAAK,WAAW;IAC1C,SAAS;AACX;AAEA,MAAM,iDAAa,CAAA,GAAA,YAAI,EAAE,cAA+B;AACxD,MAA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AE,qCAAe,OAAO,CAAC;IAC5G,OAAO,aAAa,CAAC,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC;AACvC;AAIO,MAAM,4CAAe,OAAO,CAAA,GAAA,YAAI,CAAC,CAAC,QAAQ,KAAK,aAAa,2CAAqB;AAExF,SAAS;IACP,OAAO;AACT;AAEA,SAAS;IACP,OAAO;AACT;AAEA,6DAA6D;AAC7D,SAAS,gCAAU,aAAyB;IAC1C,OAAO;IACP,OAAO,KAAO;AAChB;AAOO,SAAS;IACd,iGAAiG;IACjG,IAAI,OAAO,CAAA,GAAA,YAAI,CAAC,CAAC,uBAAuB,KAAK,YAC3C,OAAO,CAAA,GAAA,YAAI,CAAC,CAAC,uBAAuB,CAAC,iCAAW,mCAAa;IAG/D,sDAAsD;IACtD,OAAO,CAAA,GAAA,iBAAS,EAAE;AACpB;;CD3LC","sources":["packages/@react-aria/ssr/src/index.ts","packages/@react-aria/ssr/src/SSRProvider.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {SSRProvider, useSSRSafeId, useIsSSR} from './SSRProvider';\nexport type {SSRProviderProps} from './SSRProvider';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// We must avoid a circular dependency with @react-aria/utils, and this useLayoutEffect is\n// guarded by a check that it only runs on the client side.\n// eslint-disable-next-line rulesdir/useLayoutEffectRule\nimport React, {ReactNode, useContext, useLayoutEffect, useMemo, useRef, useState} from 'react';\n\n// To support SSR, the auto incrementing id counter is stored in a context. This allows\n// it to be reset on every request to ensure the client and server are consistent.\n// There is also a prefix string that is used to support async loading components\n// Each async boundary must be wrapped in an SSR provider, which appends to the prefix\n// and resets the current id counter. This ensures that async loaded components have\n// consistent ids regardless of the loading order.\ninterface SSRContextValue {\n prefix: string,\n current: number\n}\n\n// Default context value to use in case there is no SSRProvider. This is fine for\n// client-only apps. In order to support multiple copies of React Aria potentially\n// being on the page at once, the prefix is set to a random number. SSRProvider\n// will reset this to zero for consistency between server and client, so in the\n// SSR case multiple copies of React Aria is not supported.\nconst defaultContext: SSRContextValue = {\n prefix: String(Math.round(Math.random() * 10000000000)),\n current: 0\n};\n\nconst SSRContext = React.createContext<SSRContextValue>(defaultContext);\nconst IsSSRContext = React.createContext(false);\n\nexport interface SSRProviderProps {\n /** Your application here. */\n children: ReactNode\n}\n\n// This is only used in React < 18.\nfunction LegacySSRProvider(props: SSRProviderProps): JSX.Element {\n let cur = useContext(SSRContext);\n let counter = useCounter(cur === defaultContext);\n let [isSSR, setIsSSR] = useState(true);\n let value: SSRContextValue = useMemo(() => ({\n // If this is the first SSRProvider, start with an empty string prefix, otherwise\n // append and increment the counter.\n prefix: cur === defaultContext ? '' : `${cur.prefix}-${counter}`,\n current: 0\n }), [cur, counter]);\n\n // If on the client, and the component was initially server rendered,\n // then schedule a layout effect to update the component after hydration.\n if (typeof document !== 'undefined') {\n // This if statement technically breaks the rules of hooks, but is safe\n // because the condition never changes after mounting.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useLayoutEffect(() => {\n setIsSSR(false);\n }, []);\n }\n\n return (\n <SSRContext.Provider value={value}>\n <IsSSRContext.Provider value={isSSR}>\n {props.children}\n </IsSSRContext.Provider>\n </SSRContext.Provider>\n );\n}\n\nlet warnedAboutSSRProvider = false;\n\n/**\n * When using SSR with React Aria in React 16 or 17, applications must be wrapped in an SSRProvider.\n * This ensures that auto generated ids are consistent between the client and server.\n */\nexport function SSRProvider(props: SSRProviderProps): JSX.Element {\n if (typeof React['useId'] === 'function') {\n if (process.env.NODE_ENV !== 'test' && !warnedAboutSSRProvider) {\n console.warn('In React 18, SSRProvider is not necessary and is a noop. You can remove it from your app.');\n warnedAboutSSRProvider = true;\n }\n return <>{props.children}</>;\n }\n return <LegacySSRProvider {...props} />;\n}\n\nlet canUseDOM = Boolean(\n typeof window !== 'undefined' &&\n window.document &&\n window.document.createElement\n);\n\nlet componentIds = new WeakMap();\n\nfunction useCounter(isDisabled = false) {\n let ctx = useContext(SSRContext);\n let ref = useRef<number | null>(null);\n // eslint-disable-next-line rulesdir/pure-render\n if (ref.current === null && !isDisabled) {\n // In strict mode, React renders components twice, and the ref will be reset to null on the second render.\n // This means our id counter will be incremented twice instead of once. This is a problem because on the\n // server, components are only rendered once and so ids generated on the server won't match the client.\n // In React 18, useId was introduced to solve this, but it is not available in older versions. So to solve this\n // we need to use some React internals to access the underlying Fiber instance, which is stable between renders.\n // This is exposed as ReactCurrentOwner in development, which is all we need since StrictMode only runs in development.\n // To ensure that we only increment the global counter once, we store the starting id for this component in\n // a weak map associated with the Fiber. On the second render, we reset the global counter to this value.\n // Since React runs the second render immediately after the first, this is safe.\n // @ts-ignore\n let currentOwner = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?.ReactCurrentOwner?.current;\n if (currentOwner) {\n let prevComponentValue = componentIds.get(currentOwner);\n if (prevComponentValue == null) {\n // On the first render, and first call to useId, store the id and state in our weak map.\n componentIds.set(currentOwner, {\n id: ctx.current,\n state: currentOwner.memoizedState\n });\n } else if (currentOwner.memoizedState !== prevComponentValue.state) {\n // On the second render, the memoizedState gets reset by React.\n // Reset the counter, and remove from the weak map so we don't\n // do this for subsequent useId calls.\n ctx.current = prevComponentValue.id;\n componentIds.delete(currentOwner);\n }\n }\n\n // eslint-disable-next-line rulesdir/pure-render\n ref.current = ++ctx.current;\n }\n\n // eslint-disable-next-line rulesdir/pure-render\n return ref.current;\n}\n\nfunction useLegacySSRSafeId(defaultId?: string): string {\n let ctx = useContext(SSRContext);\n\n // If we are rendering in a non-DOM environment, and there's no SSRProvider,\n // provide a warning to hint to the developer to add one.\n if (ctx === defaultContext && !canUseDOM) {\n console.warn('When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.');\n }\n\n let counter = useCounter(!!defaultId);\n let prefix = ctx === defaultContext && process.env.NODE_ENV === 'test' ? 'react-aria' : `react-aria${ctx.prefix}`;\n return defaultId || `${prefix}-${counter}`;\n}\n\nfunction useModernSSRSafeId(defaultId?: string): string {\n // @ts-ignore\n let id = React.useId();\n let [didSSR] = useState(useIsSSR());\n let prefix = didSSR || process.env.NODE_ENV === 'test' ? 'react-aria' : `react-aria${defaultContext.prefix}`;\n return defaultId || `${prefix}-${id}`;\n}\n\n// Use React.useId in React 18 if available, otherwise fall back to our old implementation.\n/** @private */\nexport const useSSRSafeId = typeof React['useId'] === 'function' ? useModernSSRSafeId : useLegacySSRSafeId;\n\nfunction getSnapshot() {\n return false;\n}\n\nfunction getServerSnapshot() {\n return true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction subscribe(onStoreChange: () => void): () => void {\n // noop\n return () => {};\n}\n\n/**\n * Returns whether the component is currently being server side rendered or\n * hydrated on the client. Can be used to delay browser-specific rendering\n * until after hydration.\n */\nexport function useIsSSR(): boolean {\n // In React 18, we can use useSyncExternalStore to detect if we're server rendering or hydrating.\n if (typeof React['useSyncExternalStore'] === 'function') {\n return React['useSyncExternalStore'](subscribe, getSnapshot, getServerSnapshot);\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useContext(IsSSRContext);\n}\n"],"names":[],"version":3,"file":"module.js.map","sourceRoot":"../../../../"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";
|
|
1
|
+
{"mappings":";AAyCA;IACE,6BAA6B;IAC7B,QAAQ,EAAE,SAAS,CAAA;CACpB;AAoCD;;;GAGG;AACH,4BAA4B,KAAK,EAAE,gBAAgB,GAAG,IAAI,OAAO,CAShE;AAiED,oCAA4B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAMtD;AAGD,eAAe;AACf,OAAO,MAAM,uCAA6F,CAAC;AAgB3G;;;;GAIG;AACH,4BAA4B,OAAO,CAQlC","sources":["packages/@react-aria/ssr/src/packages/@react-aria/ssr/src/SSRProvider.tsx","packages/@react-aria/ssr/src/packages/@react-aria/ssr/src/index.ts","packages/@react-aria/ssr/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {SSRProvider, useSSRSafeId, useIsSSR} from './SSRProvider';\nexport type {SSRProviderProps} from './SSRProvider';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/ssr",
|
|
3
|
-
"version": "3.7.2-nightly.
|
|
3
|
+
"version": "3.7.2-nightly.4092+9669c4429",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"context": "node"
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "9669c44292e5f2be9b6a16b2977f61c12d79eaca"
|
|
45
45
|
}
|
package/src/SSRProvider.tsx
CHANGED
|
@@ -23,8 +23,7 @@ import React, {ReactNode, useContext, useLayoutEffect, useMemo, useRef, useState
|
|
|
23
23
|
// consistent ids regardless of the loading order.
|
|
24
24
|
interface SSRContextValue {
|
|
25
25
|
prefix: string,
|
|
26
|
-
current: number
|
|
27
|
-
isSSR: boolean
|
|
26
|
+
current: number
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
// Default context value to use in case there is no SSRProvider. This is fine for
|
|
@@ -34,11 +33,11 @@ interface SSRContextValue {
|
|
|
34
33
|
// SSR case multiple copies of React Aria is not supported.
|
|
35
34
|
const defaultContext: SSRContextValue = {
|
|
36
35
|
prefix: String(Math.round(Math.random() * 10000000000)),
|
|
37
|
-
current: 0
|
|
38
|
-
isSSR: false
|
|
36
|
+
current: 0
|
|
39
37
|
};
|
|
40
38
|
|
|
41
39
|
const SSRContext = React.createContext<SSRContextValue>(defaultContext);
|
|
40
|
+
const IsSSRContext = React.createContext(false);
|
|
42
41
|
|
|
43
42
|
export interface SSRProviderProps {
|
|
44
43
|
/** Your application here. */
|
|
@@ -54,9 +53,8 @@ function LegacySSRProvider(props: SSRProviderProps): JSX.Element {
|
|
|
54
53
|
// If this is the first SSRProvider, start with an empty string prefix, otherwise
|
|
55
54
|
// append and increment the counter.
|
|
56
55
|
prefix: cur === defaultContext ? '' : `${cur.prefix}-${counter}`,
|
|
57
|
-
current: 0
|
|
58
|
-
|
|
59
|
-
}), [cur, counter, isSSR]);
|
|
56
|
+
current: 0
|
|
57
|
+
}), [cur, counter]);
|
|
60
58
|
|
|
61
59
|
// If on the client, and the component was initially server rendered,
|
|
62
60
|
// then schedule a layout effect to update the component after hydration.
|
|
@@ -71,7 +69,9 @@ function LegacySSRProvider(props: SSRProviderProps): JSX.Element {
|
|
|
71
69
|
|
|
72
70
|
return (
|
|
73
71
|
<SSRContext.Provider value={value}>
|
|
74
|
-
{
|
|
72
|
+
<IsSSRContext.Provider value={isSSR}>
|
|
73
|
+
{props.children}
|
|
74
|
+
</IsSSRContext.Provider>
|
|
75
75
|
</SSRContext.Provider>
|
|
76
76
|
);
|
|
77
77
|
}
|
|
@@ -194,6 +194,5 @@ export function useIsSSR(): boolean {
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
197
|
-
|
|
198
|
-
return cur.isSSR;
|
|
197
|
+
return useContext(IsSSRContext);
|
|
199
198
|
}
|