next-sanity 8.4.5 → 8.5.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/dist/image/Image.cjs +1 -1
- package/dist/image/Image.cjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/preview/index.cjs +1 -1
- package/dist/studio/NextStudio.cjs +1 -1
- package/dist/studio/NextStudio.cjs.map +1 -1
- package/dist/studio/NextStudio.js +1 -1
- package/dist/studio/NextStudio.js.map +1 -1
- package/dist/studio/createHashHistoryForStudio.cjs +1 -0
- package/dist/studio/createHashHistoryForStudio.cjs.map +1 -0
- package/dist/studio/createHashHistoryForStudio.js +1 -0
- package/dist/studio/createHashHistoryForStudio.js.map +1 -0
- package/dist/studio/index.d.cts +15 -1
- package/dist/studio/index.d.ts +15 -1
- package/dist/studio/registry.cjs +1 -1
- package/dist/studio/registry.cjs.map +1 -1
- package/dist/studio/registry.js +1 -1
- package/dist/studio/registry.js.map +1 -1
- package/dist/studio/useIsMounted.cjs +1 -0
- package/dist/studio/useIsMounted.cjs.map +1 -0
- package/dist/studio/useIsMounted.js +1 -0
- package/dist/studio/useIsMounted.js.map +1 -0
- package/package.json +7 -6
- package/src/studio/NextStudio.tsx +35 -5
- package/src/studio/createHashHistoryForStudio.ts +44 -0
- package/src/studio/registry.tsx +8 -9
- package/src/studio/useIsMounted.ts +12 -0
package/dist/image/Image.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("next/image"),t=require("./imageLoader.cjs");function a(e){return e&&e
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("next/image"),t=require("./imageLoader.cjs");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=a(r);exports.Image=function(r){const{loader:a,src:s,...i}=r;if(a)throw new TypeError("The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.");let n;try{n=new URL(s),r.height&&n.searchParams.set("h",`${r.height}`),r.width&&n.searchParams.set("w",`${r.width}`)}catch(e){throw new TypeError("The `src` prop must be a valid URL to an image on the Sanity Image CDN.",{cause:e})}return e.jsx(o.default,{...i,src:n.toString(),loader:t.imageLoader})};//# sourceMappingURL=Image.cjs.map
|
package/dist/image/Image.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Image.cjs","sources":["../../src/image/Image.tsx"],"sourcesContent":["import NextImage, {ImageProps as NextImageProps} from 'next/image'\n\nimport {imageLoader} from './imageLoader'\n\n/**\n * @alpha\n */\nexport interface ImageProps extends Omit<NextImageProps, 'loader' | 'src'> {\n /**\n * The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.\n */\n loader?: never\n /**\n * Must be a string that is a valid URL to an image on the Sanity Image CDN.\n */\n src: string\n}\n\n/**\n * @alpha\n */\nexport function Image(props: ImageProps): JSX.Element {\n const {loader, src, ...rest} = props\n if (loader) {\n throw new TypeError(\n 'The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.',\n )\n }\n let srcUrl: URL\n try {\n srcUrl = new URL(src)\n if (props.height) {\n srcUrl.searchParams.set('h', `${props.height}`)\n }\n if (props.width) {\n srcUrl.searchParams.set('w', `${props.width}`)\n }\n } catch (err) {\n throw new TypeError(\n 'The `src` prop must be a valid URL to an image on the Sanity Image CDN.',\n {cause: err},\n )\n }\n return <NextImage {...rest} src={srcUrl.toString()} loader={imageLoader} />\n}\n"],"names":["exports","Image","props","loader","src","rest","TypeError","srcUrl","URL","height","searchParams","set","width","err","cause","NextImage","toString","imageLoader"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Image.cjs","sources":["../../src/image/Image.tsx"],"sourcesContent":["import NextImage, {ImageProps as NextImageProps} from 'next/image'\n\nimport {imageLoader} from './imageLoader'\n\n/**\n * @alpha\n */\nexport interface ImageProps extends Omit<NextImageProps, 'loader' | 'src'> {\n /**\n * The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.\n */\n loader?: never\n /**\n * Must be a string that is a valid URL to an image on the Sanity Image CDN.\n */\n src: string\n}\n\n/**\n * @alpha\n */\nexport function Image(props: ImageProps): JSX.Element {\n const {loader, src, ...rest} = props\n if (loader) {\n throw new TypeError(\n 'The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.',\n )\n }\n let srcUrl: URL\n try {\n srcUrl = new URL(src)\n if (props.height) {\n srcUrl.searchParams.set('h', `${props.height}`)\n }\n if (props.width) {\n srcUrl.searchParams.set('w', `${props.width}`)\n }\n } catch (err) {\n throw new TypeError(\n 'The `src` prop must be a valid URL to an image on the Sanity Image CDN.',\n {cause: err},\n )\n }\n return <NextImage {...rest} src={srcUrl.toString()} loader={imageLoader} />\n}\n"],"names":["exports","Image","props","loader","src","rest","TypeError","srcUrl","URL","height","searchParams","set","width","err","cause","NextImage","toString","imageLoader"],"mappings":"iPA4CAA,QAAAC,MAvBO,SAAeC,GACpB,MAAMC,OAACA,EAAAC,IAAQA,KAAQC,GAAQH,EAC3B,GAAAC,EACF,MAAM,IAAIG,UACR,+GAGA,IAAAC,EACA,IACOA,EAAA,IAAIC,IAAIJ,GACbF,EAAMO,QACRF,EAAOG,aAAaC,IAAI,IAAK,GAAGT,EAAMO,UAEpCP,EAAMU,OACRL,EAAOG,aAAaC,IAAI,IAAK,GAAGT,EAAMU,eAEjCC,GACP,MAAM,IAAIP,UACR,0EACA,CAACQ,MAAOD,GAEZ,CACO,aAACE,EAAAA,YAAcV,EAAMD,IAAKG,EAAOS,WAAYb,OAAQc,EAAAA,aAC9D"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@sanity/client"),t=require("./visual-editing/index.cjs"),r=require("@portabletext/react"),n=require("groq"),i=require("@sanity/visual-editing/create-data-attribute");function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@sanity/client"),t=require("./visual-editing/index.cjs"),r=require("@portabletext/react"),n=require("groq"),i=require("@sanity/visual-editing/create-data-attribute");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=a(n);Object.defineProperty(exports,"createClient",{enumerable:!0,get:function(){return e.createClient}}),Object.defineProperty(exports,"unstable__adapter",{enumerable:!0,get:function(){return e.unstable__adapter}}),Object.defineProperty(exports,"unstable__environment",{enumerable:!0,get:function(){return e.unstable__environment}}),exports.VisualEditing=t.VisualEditing,Object.defineProperty(exports,"groq",{enumerable:!0,get:function(){return u.default}}),Object.defineProperty(exports,"createDataAttribute",{enumerable:!0,get:function(){return i.createDataAttribute}}),Object.keys(r).forEach((function(e){"default"!==e&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return r[e]}})}));//# sourceMappingURL=index.cjs.map
|
package/dist/preview/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@sanity/preview-kit");function r(e){return e&&e
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@sanity/preview-kit");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=r(e);Object.defineProperty(exports,"LiveQueryProvider",{enumerable:!0,get:function(){return e.LiveQueryProvider}}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return t.default}}),Object.defineProperty(exports,"useLiveQuery",{enumerable:!0,get:function(){return e.useLiveQuery}});//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("sanity"),
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("sanity"),s=require("./createHashHistoryForStudio.cjs"),o=require("./NextStudioLayout.cjs"),i=require("./NextStudioNoScript.cjs"),u=require("./registry.cjs"),n=require("./useIsMounted.cjs");const a=t.memo((({children:a,config:c,unstable__noScript:h=!0,scheme:l,history:d,...y})=>{const x=n.useIsMounted(),S=t.useMemo((()=>{if(y.unstable_history&&d)throw new Error("Cannot use both `unstable_history` and `history` props at the same time");return x&&"hash"===d?s.createHashHistoryForStudio():y.unstable_history}),[d,x,y.unstable_history]);return e.jsxs(e.Fragment,{children:[h&&e.jsx(i.NextStudioNoScript,{}),e.jsx(u.StyledComponentsRegistry,{isMounted:x,children:e.jsx(o.NextStudioLayout,{children:"hash"!==d||x?a||e.jsx(r.Studio,{config:c,scheme:l,unstable_globalStyles:!0,...y,unstable_history:S}):null})})]})}));exports.NextStudio=a;//# sourceMappingURL=NextStudio.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NextStudio.cjs","sources":["../../src/studio/NextStudio.tsx"],"sourcesContent":["'use client'\n\nimport {memo} from 'react'\nimport {Studio, type StudioProps} from 'sanity'\n\nimport {NextStudioLayout} from './NextStudioLayout'\nimport {NextStudioNoScript} from './NextStudioNoScript'\nimport {StyledComponentsRegistry} from './registry'\n\n/** @public */\nexport interface NextStudioProps extends StudioProps {\n children?: React.ReactNode\n /**\n * Render the <noscript> tag\n * @defaultValue true\n * @alpha\n */\n unstable__noScript?: boolean\n}\n/**\n * Intended to render at the root of a page, letting the Studio own that page and render much like it would if you used `npx sanity start` to render\n * It's a drop-in replacement for `import {Studio} from 'sanity'`\n */\nconst NextStudioComponent = ({\n children,\n config,\n unstable__noScript = true,\n scheme,\n ...props\n}: NextStudioProps) => {\n return (\n <>\n {unstable__noScript && <NextStudioNoScript />}\n <StyledComponentsRegistry>\n <NextStudioLayout>\n {children || (\n
|
|
1
|
+
{"version":3,"file":"NextStudio.cjs","sources":["../../src/studio/NextStudio.tsx"],"sourcesContent":["'use client'\n\nimport {memo, useMemo} from 'react'\nimport {Studio, type StudioProps} from 'sanity'\n\nimport {createHashHistoryForStudio} from './createHashHistoryForStudio'\nimport {NextStudioLayout} from './NextStudioLayout'\nimport {NextStudioNoScript} from './NextStudioNoScript'\nimport {StyledComponentsRegistry} from './registry'\nimport {useIsMounted} from './useIsMounted'\n\n/** @public */\nexport interface NextStudioProps extends StudioProps {\n children?: React.ReactNode\n /**\n * Render the <noscript> tag\n * @defaultValue true\n * @alpha\n */\n unstable__noScript?: boolean\n /**\n * The 'hash' option is new feature that is not yet stable for production, but is available for testing and its API won't change in a breaking way.\n * If 'hash' doesn't work for you, or if you want to use a memory based history, you can use the `unstable_history` prop instead.\n * @alpha\n * @defaultValue 'browser'\n */\n history?: 'browser' | 'hash'\n}\n/**\n * Intended to render at the root of a page, letting the Studio own that page and render much like it would if you used `npx sanity start` to render\n * It's a drop-in replacement for `import {Studio} from 'sanity'`\n */\nconst NextStudioComponent = ({\n children,\n config,\n unstable__noScript = true,\n scheme,\n history,\n ...props\n}: NextStudioProps) => {\n const isMounted = useIsMounted()\n const unstableHistory = useMemo<typeof props.unstable_history>(() => {\n if (props.unstable_history && history) {\n throw new Error('Cannot use both `unstable_history` and `history` props at the same time')\n }\n\n if (isMounted && history === 'hash') {\n return createHashHistoryForStudio()\n }\n return props.unstable_history\n }, [history, isMounted, props.unstable_history])\n\n return (\n <>\n {unstable__noScript && <NextStudioNoScript />}\n <StyledComponentsRegistry isMounted={isMounted}>\n <NextStudioLayout>\n {history === 'hash' && !isMounted\n ? null\n : children || (\n <Studio\n config={config}\n scheme={scheme}\n unstable_globalStyles\n {...props}\n unstable_history={unstableHistory}\n />\n )}\n </NextStudioLayout>\n </StyledComponentsRegistry>\n </>\n )\n}\n\n/**\n * Override how the Studio renders by passing children.\n * This is useful for advanced use cases where you're using StudioProvider and StudioLayout instead of Studio:\n * ```\n * import {StudioProvider, StudioLayout} from 'sanity'\n * import {NextStudio} from 'next-sanity/studio'\n * <NextStudio config={config}>\n * <StudioProvider config={config}>\n * <CustomComponentThatUsesContextFromStudioProvider />\n * <StudioLayout />\n * </StudioProvider>\n * </NextStudio>\n * ```\n * @public\n */\nexport const NextStudio = memo(NextStudioComponent)\n"],"names":["NextStudio","memo","children","config","unstable__noScript","scheme","history","props","isMounted","useIsMounted","unstableHistory","useMemo","unstable_history","Error","createHashHistoryForStudio","jsxRuntime","jsxs","Fragment","NextStudioNoScript","jsx","StyledComponentsRegistry","NextStudioLayout","Studio","unstable_globalStyles","exports"],"mappings":"+UAgCA,MAyDaA,EAAaC,QAzDE,EAC1BC,WACAC,SACAC,sBAAqB,EACrBC,SACAC,aACGC,MAEH,MAAMC,EAAYC,EAAAA,eACZC,EAAkBC,WAAuC,KAC7D,GAAIJ,EAAMK,kBAAoBN,EACtB,MAAA,IAAIO,MAAM,2EAGlB,OAAIL,GAAyB,SAAZF,EACRQ,EAAAA,6BAEFP,EAAMK,gBAAA,GACZ,CAACN,EAASE,EAAWD,EAAMK,mBAE9B,OAEKG,EAAAC,KAAAC,WAAA,CAAAf,SAAA,CAAAE,SAAuBc,EAAmBA,mBAAA,MAC3CC,IAACC,EAAAA,yBAAyB,CAAAZ,YACxBN,SAACa,EAAAI,IAAAE,EAAAA,iBAAA,CACEnB,SAAY,YAAWM,EAEpBN,GACEa,EAAAI,IAACG,EAAAA,OAAA,CACCnB,SACAE,SACAkB,uBAAqB,KACjBhB,EACJK,iBAAkBF,IAPtB,WAYV,IAmB8Cc,QAAAxB,WAAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsxs as
|
|
1
|
+
"use client";import{jsxs as t,Fragment as r,jsx as o}from"react/jsx-runtime";import{memo as s,useMemo as e}from"react";import{Studio as i}from"sanity";import{createHashHistoryForStudio as n}from"./createHashHistoryForStudio.js";import{NextStudioLayout as h}from"./NextStudioLayout.js";import{NextStudioNoScript as m}from"./NextStudioNoScript.js";import{StyledComponentsRegistry as a}from"./registry.js";import{useIsMounted as u}from"./useIsMounted.js";const l=s((({children:s,config:l,unstable__noScript:c=!0,scheme:p,history:y,...f})=>{const d=u(),b=e((()=>{if(f.unstable_history&&y)throw new Error("Cannot use both `unstable_history` and `history` props at the same time");return d&&"hash"===y?n():f.unstable_history}),[y,d,f.unstable_history]);return t(r,{children:[c&&o(m,{}),o(a,{isMounted:d,children:o(h,{children:"hash"!==y||d?s||o(i,{config:l,scheme:p,unstable_globalStyles:!0,...f,unstable_history:b}):null})})]})}));export{l as NextStudio};//# sourceMappingURL=NextStudio.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NextStudio.js","sources":["../../src/studio/NextStudio.tsx"],"sourcesContent":["'use client'\n\nimport {memo} from 'react'\nimport {Studio, type StudioProps} from 'sanity'\n\nimport {NextStudioLayout} from './NextStudioLayout'\nimport {NextStudioNoScript} from './NextStudioNoScript'\nimport {StyledComponentsRegistry} from './registry'\n\n/** @public */\nexport interface NextStudioProps extends StudioProps {\n children?: React.ReactNode\n /**\n * Render the <noscript> tag\n * @defaultValue true\n * @alpha\n */\n unstable__noScript?: boolean\n}\n/**\n * Intended to render at the root of a page, letting the Studio own that page and render much like it would if you used `npx sanity start` to render\n * It's a drop-in replacement for `import {Studio} from 'sanity'`\n */\nconst NextStudioComponent = ({\n children,\n config,\n unstable__noScript = true,\n scheme,\n ...props\n}: NextStudioProps) => {\n return (\n <>\n {unstable__noScript && <NextStudioNoScript />}\n <StyledComponentsRegistry>\n <NextStudioLayout>\n {children || (\n
|
|
1
|
+
{"version":3,"file":"NextStudio.js","sources":["../../src/studio/NextStudio.tsx"],"sourcesContent":["'use client'\n\nimport {memo, useMemo} from 'react'\nimport {Studio, type StudioProps} from 'sanity'\n\nimport {createHashHistoryForStudio} from './createHashHistoryForStudio'\nimport {NextStudioLayout} from './NextStudioLayout'\nimport {NextStudioNoScript} from './NextStudioNoScript'\nimport {StyledComponentsRegistry} from './registry'\nimport {useIsMounted} from './useIsMounted'\n\n/** @public */\nexport interface NextStudioProps extends StudioProps {\n children?: React.ReactNode\n /**\n * Render the <noscript> tag\n * @defaultValue true\n * @alpha\n */\n unstable__noScript?: boolean\n /**\n * The 'hash' option is new feature that is not yet stable for production, but is available for testing and its API won't change in a breaking way.\n * If 'hash' doesn't work for you, or if you want to use a memory based history, you can use the `unstable_history` prop instead.\n * @alpha\n * @defaultValue 'browser'\n */\n history?: 'browser' | 'hash'\n}\n/**\n * Intended to render at the root of a page, letting the Studio own that page and render much like it would if you used `npx sanity start` to render\n * It's a drop-in replacement for `import {Studio} from 'sanity'`\n */\nconst NextStudioComponent = ({\n children,\n config,\n unstable__noScript = true,\n scheme,\n history,\n ...props\n}: NextStudioProps) => {\n const isMounted = useIsMounted()\n const unstableHistory = useMemo<typeof props.unstable_history>(() => {\n if (props.unstable_history && history) {\n throw new Error('Cannot use both `unstable_history` and `history` props at the same time')\n }\n\n if (isMounted && history === 'hash') {\n return createHashHistoryForStudio()\n }\n return props.unstable_history\n }, [history, isMounted, props.unstable_history])\n\n return (\n <>\n {unstable__noScript && <NextStudioNoScript />}\n <StyledComponentsRegistry isMounted={isMounted}>\n <NextStudioLayout>\n {history === 'hash' && !isMounted\n ? null\n : children || (\n <Studio\n config={config}\n scheme={scheme}\n unstable_globalStyles\n {...props}\n unstable_history={unstableHistory}\n />\n )}\n </NextStudioLayout>\n </StyledComponentsRegistry>\n </>\n )\n}\n\n/**\n * Override how the Studio renders by passing children.\n * This is useful for advanced use cases where you're using StudioProvider and StudioLayout instead of Studio:\n * ```\n * import {StudioProvider, StudioLayout} from 'sanity'\n * import {NextStudio} from 'next-sanity/studio'\n * <NextStudio config={config}>\n * <StudioProvider config={config}>\n * <CustomComponentThatUsesContextFromStudioProvider />\n * <StudioLayout />\n * </StudioProvider>\n * </NextStudio>\n * ```\n * @public\n */\nexport const NextStudio = memo(NextStudioComponent)\n"],"names":["NextStudio","memo","children","config","unstable__noScript","scheme","history","props","isMounted","useIsMounted","unstableHistory","useMemo","unstable_history","Error","createHashHistoryForStudio","jsxs","Fragment","NextStudioNoScript","jsx","StyledComponentsRegistry","NextStudioLayout","Studio","unstable_globalStyles"],"mappings":"ocAgCA,MAyDaA,EAAaC,GAzDE,EAC1BC,WACAC,SACAC,sBAAqB,EACrBC,SACAC,aACGC,MAEH,MAAMC,EAAYC,IACZC,EAAkBC,GAAuC,KAC7D,GAAIJ,EAAMK,kBAAoBN,EACtB,MAAA,IAAIO,MAAM,2EAGlB,OAAIL,GAAyB,SAAZF,EACRQ,IAEFP,EAAMK,gBAAA,GACZ,CAACN,EAASE,EAAWD,EAAMK,mBAIzB,OAAAG,EAAAC,EAAA,CAAAd,SAAA,CAAAE,KAAuBa,EAAmB,IAC1CC,EAAAC,EAAyB,CAAAX,YACxBN,SAACgB,EAAAE,EAAA,CACElB,SAAY,YAAWM,EAEpBN,GACEgB,EAACG,EAAA,CACClB,SACAE,SACAiB,uBAAqB,KACjBf,EACJK,iBAAkBF,IAPtB,WAYV"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("history");exports.createHashHistoryForStudio=function(){const r=e.createHashHistory();return{get action(){return r.action},get location(){return r.location},get createHref(){return r.createHref},get push(){return r.push},get replace(){return r.replace},get go(){return r.go},get back(){return r.back},get forward(){return r.forward},get block(){return r.block},listen:e=>r.listen((({location:r})=>{e(r)}))}};//# sourceMappingURL=createHashHistoryForStudio.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHashHistoryForStudio.cjs","sources":["../../src/studio/createHashHistoryForStudio.ts"],"sourcesContent":["import {createHashHistory, type History, type Listener} from 'history'\n\n/** @internal */\nexport function createHashHistoryForStudio(): History {\n const history = createHashHistory()\n return {\n get action() {\n return history.action\n },\n get location() {\n return history.location\n },\n get createHref() {\n return history.createHref\n },\n get push() {\n return history.push\n },\n get replace() {\n return history.replace\n },\n get go() {\n return history.go\n },\n get back() {\n return history.back\n },\n get forward() {\n return history.forward\n },\n get block() {\n return history.block\n },\n // Overriding listen to workaround a problem where native history provides history.listen(location => void), but the npm package is history.listen(({action, location}) => void)\n listen(listener: Listener) {\n // return history.listen(({ action, location }) => {\n return history.listen(({location}) => {\n // console.debug('history.listen', action, location)\n // @ts-expect-error -- working around a bug? in studio\n listener(location)\n })\n },\n }\n}\n"],"names":["Object","defineProperty","exports","value","history","require","createHashHistoryForStudio","createHashHistory","action","location","createHref","push","replace","go","back","forward","block","listen","listener"],"mappings":"aAGOA,OAAAC,eAAAC,QAAA,aAAA,CAAAC,OAAA,IAAA,IAAAC,EAAAC,QAAA,WAwCPH,QAAAI,2BAxCO,WACCF,MAAAA,EAAUG,EAAAA,oBACT,MAAA,CACL,UAAIC,GACF,OAAOJ,EAAQI,MACjB,EACA,YAAIC,GACF,OAAOL,EAAQK,QACjB,EACA,cAAIC,GACF,OAAON,EAAQM,UACjB,EACA,QAAIC,GACF,OAAOP,EAAQO,IACjB,EACA,WAAIC,GACF,OAAOR,EAAQQ,OACjB,EACA,MAAIC,GACF,OAAOT,EAAQS,EACjB,EACA,QAAIC,GACF,OAAOV,EAAQU,IACjB,EACA,WAAIC,GACF,OAAOX,EAAQW,OACjB,EACA,SAAIC,GACF,OAAOZ,EAAQY,KACjB,EAEAC,OAAOC,GAEEd,EAAQa,QAAO,EAAER,eAGtBS,EAAST,EAAQ,IAIzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createHashHistory as r}from"history";function t(){const t=r();return{get action(){return t.action},get location(){return t.location},get createHref(){return t.createHref},get push(){return t.push},get replace(){return t.replace},get go(){return t.go},get back(){return t.back},get forward(){return t.forward},get block(){return t.block},listen:r=>t.listen((({location:t})=>{r(t)}))}}export{t as createHashHistoryForStudio};//# sourceMappingURL=createHashHistoryForStudio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHashHistoryForStudio.js","sources":["../../src/studio/createHashHistoryForStudio.ts"],"sourcesContent":["import {createHashHistory, type History, type Listener} from 'history'\n\n/** @internal */\nexport function createHashHistoryForStudio(): History {\n const history = createHashHistory()\n return {\n get action() {\n return history.action\n },\n get location() {\n return history.location\n },\n get createHref() {\n return history.createHref\n },\n get push() {\n return history.push\n },\n get replace() {\n return history.replace\n },\n get go() {\n return history.go\n },\n get back() {\n return history.back\n },\n get forward() {\n return history.forward\n },\n get block() {\n return history.block\n },\n // Overriding listen to workaround a problem where native history provides history.listen(location => void), but the npm package is history.listen(({action, location}) => void)\n listen(listener: Listener) {\n // return history.listen(({ action, location }) => {\n return history.listen(({location}) => {\n // console.debug('history.listen', action, location)\n // @ts-expect-error -- working around a bug? in studio\n listener(location)\n })\n },\n }\n}\n"],"names":["createHashHistory","createHashHistoryForStudio","history","action","location","createHref","push","replace","go","back","forward","block","listen","listener"],"mappings":"4BAGOA,MAAA,UAAA,SAASC,IACd,MAAMC,EAAUF,IACT,MAAA,CACL,UAAIG,GACF,OAAOD,EAAQC,MACjB,EACA,YAAIC,GACF,OAAOF,EAAQE,QACjB,EACA,cAAIC,GACF,OAAOH,EAAQG,UACjB,EACA,QAAIC,GACF,OAAOJ,EAAQI,IACjB,EACA,WAAIC,GACF,OAAOL,EAAQK,OACjB,EACA,MAAIC,GACF,OAAON,EAAQM,EACjB,EACA,QAAIC,GACF,OAAOP,EAAQO,IACjB,EACA,WAAIC,GACF,OAAOR,EAAQQ,OACjB,EACA,SAAIC,GACF,OAAOT,EAAQS,KACjB,EAEAC,OAAOC,GAEEX,EAAQU,QAAO,EAAER,eAGtBS,EAAST,EAAQ,IAIzB"}
|
package/dist/studio/index.d.cts
CHANGED
|
@@ -43,7 +43,14 @@ export declare const metadata: {
|
|
|
43
43
|
* @public
|
|
44
44
|
*/
|
|
45
45
|
export declare const NextStudio: MemoExoticComponent<
|
|
46
|
-
({
|
|
46
|
+
({
|
|
47
|
+
children,
|
|
48
|
+
config,
|
|
49
|
+
unstable__noScript,
|
|
50
|
+
scheme,
|
|
51
|
+
history,
|
|
52
|
+
...props
|
|
53
|
+
}: NextStudioProps) => JSX_2.Element
|
|
47
54
|
>
|
|
48
55
|
|
|
49
56
|
/** @public */
|
|
@@ -68,6 +75,13 @@ export declare interface NextStudioProps extends StudioProps {
|
|
|
68
75
|
* @alpha
|
|
69
76
|
*/
|
|
70
77
|
unstable__noScript?: boolean
|
|
78
|
+
/**
|
|
79
|
+
* The 'hash' option is new feature that is not yet stable for production, but is available for testing and its API won't change in a breaking way.
|
|
80
|
+
* If 'hash' doesn't work for you, or if you want to use a memory based history, you can use the `unstable_history` prop instead.
|
|
81
|
+
* @alpha
|
|
82
|
+
* @defaultValue 'browser'
|
|
83
|
+
*/
|
|
84
|
+
history?: 'browser' | 'hash'
|
|
71
85
|
}
|
|
72
86
|
|
|
73
87
|
/**
|
package/dist/studio/index.d.ts
CHANGED
|
@@ -43,7 +43,14 @@ export declare const metadata: {
|
|
|
43
43
|
* @public
|
|
44
44
|
*/
|
|
45
45
|
export declare const NextStudio: MemoExoticComponent<
|
|
46
|
-
({
|
|
46
|
+
({
|
|
47
|
+
children,
|
|
48
|
+
config,
|
|
49
|
+
unstable__noScript,
|
|
50
|
+
scheme,
|
|
51
|
+
history,
|
|
52
|
+
...props
|
|
53
|
+
}: NextStudioProps) => JSX_2.Element
|
|
47
54
|
>
|
|
48
55
|
|
|
49
56
|
/** @public */
|
|
@@ -68,6 +75,13 @@ export declare interface NextStudioProps extends StudioProps {
|
|
|
68
75
|
* @alpha
|
|
69
76
|
*/
|
|
70
77
|
unstable__noScript?: boolean
|
|
78
|
+
/**
|
|
79
|
+
* The 'hash' option is new feature that is not yet stable for production, but is available for testing and its API won't change in a breaking way.
|
|
80
|
+
* If 'hash' doesn't work for you, or if you want to use a memory based history, you can use the `unstable_history` prop instead.
|
|
81
|
+
* @alpha
|
|
82
|
+
* @defaultValue 'browser'
|
|
83
|
+
*/
|
|
84
|
+
history?: 'browser' | 'hash'
|
|
71
85
|
}
|
|
72
86
|
|
|
73
87
|
/**
|
package/dist/studio/registry.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("next/navigation.js"),r=require("react"),n=require("styled-components");
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("next/navigation.js"),r=require("react"),n=require("styled-components");exports.StyledComponentsRegistry=function({children:s,isMounted:i}){const[a]=r.useState((()=>new n.ServerStyleSheet));return t.useServerInsertedHTML((()=>{const t=a.getStyleElement();return a.instance.clearTag(),e.jsx(e.Fragment,{children:t})})),i?e.jsx(e.Fragment,{children:s}):e.jsx(n.StyleSheetManager,{sheet:a.instance,children:s})};//# sourceMappingURL=registry.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.cjs","sources":["../../src/studio/registry.tsx"],"sourcesContent":["// https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components\nimport {useServerInsertedHTML} from 'next/navigation.js'\nimport {useState
|
|
1
|
+
{"version":3,"file":"registry.cjs","sources":["../../src/studio/registry.tsx"],"sourcesContent":["// https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components\nimport {useServerInsertedHTML} from 'next/navigation.js'\nimport {useState} from 'react'\nimport {ServerStyleSheet, StyleSheetManager} from 'styled-components'\n\nexport function StyledComponentsRegistry({\n children,\n isMounted,\n}: {\n children: React.ReactNode\n isMounted: boolean\n}): JSX.Element {\n // Only create stylesheet once with lazy initial state\n // x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state\n const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())\n\n useServerInsertedHTML(() => {\n const styles = styledComponentsStyleSheet.getStyleElement()\n styledComponentsStyleSheet.instance.clearTag()\n return <>{styles}</>\n })\n\n if (isMounted) return <>{children}</>\n\n return (\n <StyleSheetManager sheet={styledComponentsStyleSheet.instance}>{children}</StyleSheetManager>\n )\n}\n"],"names":["Object","defineProperty","exports","value","jsxRuntime","require","navigation_js","react","styledComponents","StyledComponentsRegistry","children","isMounted","styledComponentsStyleSheet","useState","ServerStyleSheet","useServerInsertedHTML","styles","getStyleElement","instance","clearTag","jsx","Fragment","StyleSheetManager","sheet"],"mappings":"aAKOA,OAAAC,eAAAC,QAAA,aAAA,CAAAC,OAAA,IAAA,IAAAC,EAAAC,QAAA,qBAAAC,EAAAD,QAAA,sBAAAE,EAAAF,QAAA,SAAAG,EAAAH,QAAA,qBAsBPH,QAAAO,yBAtBO,UAAkCC,SACvCA,EAAAC,UACAA,IAOM,MAACC,GAA8BC,EAAAA,UAAS,IAAM,IAAIC,EAAAA,mBAExDC,OAAAA,yBAAsB,KACd,MAAAC,EAASJ,EAA2BK,kBAC1C,OAAAL,EAA2BM,SAASC,WAC7BC,EAAAA,IAAAC,EAAAA,SAAA,CAAGX,SAAOM,GAAA,IAGfL,EAAqBS,EAAAA,IAAAC,EAAAA,SAAA,CAAAX,aAGvBN,EAAAgB,IAACE,EAAkBA,kBAAA,CAAAC,MAAOX,EAA2BM,SAAWR,YAEpE"}
|
package/dist/studio/registry.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as e,Fragment as t}from"react/jsx-runtime";import{useServerInsertedHTML as n}from"next/navigation.js";import{useState as r}from"react";import{ServerStyleSheet as o,StyleSheetManager as i}from"styled-components";function c({children:c,isMounted:m}){const[s]=r((()=>new o));return n((()=>{const n=s.getStyleElement();return s.instance.clearTag(),e(t,{children:n})})),m?e(t,{children:c}):e(i,{sheet:s.instance,children:c})}export{c as StyledComponentsRegistry};//# sourceMappingURL=registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sources":["../../src/studio/registry.tsx"],"sourcesContent":["// https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components\nimport {useServerInsertedHTML} from 'next/navigation.js'\nimport {useState
|
|
1
|
+
{"version":3,"file":"registry.js","sources":["../../src/studio/registry.tsx"],"sourcesContent":["// https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components\nimport {useServerInsertedHTML} from 'next/navigation.js'\nimport {useState} from 'react'\nimport {ServerStyleSheet, StyleSheetManager} from 'styled-components'\n\nexport function StyledComponentsRegistry({\n children,\n isMounted,\n}: {\n children: React.ReactNode\n isMounted: boolean\n}): JSX.Element {\n // Only create stylesheet once with lazy initial state\n // x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state\n const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())\n\n useServerInsertedHTML(() => {\n const styles = styledComponentsStyleSheet.getStyleElement()\n styledComponentsStyleSheet.instance.clearTag()\n return <>{styles}</>\n })\n\n if (isMounted) return <>{children}</>\n\n return (\n <StyleSheetManager sheet={styledComponentsStyleSheet.instance}>{children}</StyleSheetManager>\n )\n}\n"],"names":["jsx","Fragment","useServerInsertedHTML","useState","ServerStyleSheet","StyleSheetManager","StyledComponentsRegistry","children","isMounted","styledComponentsStyleSheet","styles","getStyleElement","instance","clearTag","sheet"],"mappings":"cAKOA,cAAAC,MAAA,oDAAAC,MAAA,wCAAAC,MAAA,mCAAAC,uBAAAC,MAAA,oBAAA,SAASC,GAAyBC,SACvCA,EAAAC,UACAA,IAOA,MAAOC,GAA8BN,GAAS,IAAM,IAAIC,IAQxD,OANAF,GAAsB,KACd,MAAAQ,EAASD,EAA2BE,kBAC1C,OAAAF,EAA2BG,SAASC,aAC7BZ,EAAA,CAAGM,SAAOG,GAAA,IAGfF,EAAqBR,EAAAC,EAAA,CAAAM,aAGvBP,EAACK,EAAkB,CAAAS,MAAOL,EAA2BG,SAAWL,YAEpE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");const r=()=>()=>{};exports.useIsMounted=function(){return e.useSyncExternalStore(r,(()=>!0),(()=>!1))};//# sourceMappingURL=useIsMounted.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIsMounted.cjs","sources":["../../src/studio/useIsMounted.ts"],"sourcesContent":["import {useSyncExternalStore} from 'react'\n\n/** @internal */\nexport function useIsMounted(): boolean {\n return useSyncExternalStore(\n emptySubscribe,\n () => true,\n () => false,\n )\n}\n// eslint-disable-next-line no-empty-function\nconst emptySubscribe = () => () => {}\n"],"names":["Object","defineProperty","exports","value","react","require","emptySubscribe","useIsMounted","useSyncExternalStore"],"mappings":"aAGOA,OAAAC,eAAAC,QAAA,aAAA,CAAAC,OAAA,IAAA,IAAAC,EAAAC,QAAA,SAQP,MAAMC,EAAiB,IAAM,OAAOJ,QAAAK,aAR7B,WACE,OAAAC,EAAAA,qBACLF,GACA,KAAM,IACN,KAAM,GAEV"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useSyncExternalStore as r}from"react";function t(){return r(o,(()=>!0),(()=>!1))}const o=()=>()=>{};export{t as useIsMounted};//# sourceMappingURL=useIsMounted.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIsMounted.js","sources":["../../src/studio/useIsMounted.ts"],"sourcesContent":["import {useSyncExternalStore} from 'react'\n\n/** @internal */\nexport function useIsMounted(): boolean {\n return useSyncExternalStore(\n emptySubscribe,\n () => true,\n () => false,\n )\n}\n// eslint-disable-next-line no-empty-function\nconst emptySubscribe = () => () => {}\n"],"names":["useSyncExternalStore","useIsMounted","emptySubscribe"],"mappings":"+BAGOA,MAAA,QAAA,SAASC,IACP,OAAAD,EACLE,GACA,KAAM,IACN,KAAM,GAEV,CAEA,MAAMA,EAAiB,IAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-sanity",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.5.0",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -110,17 +110,18 @@
|
|
|
110
110
|
],
|
|
111
111
|
"browserslist": "extends @sanity/browserslist-config",
|
|
112
112
|
"dependencies": {
|
|
113
|
-
"@portabletext/react": "^3.0.
|
|
113
|
+
"@portabletext/react": "^3.0.15",
|
|
114
114
|
"@sanity/client": "^6.15.7",
|
|
115
|
-
"@sanity/preview-kit": "5.0.
|
|
116
|
-
"@sanity/visual-editing": "1.8.
|
|
115
|
+
"@sanity/preview-kit": "5.0.36",
|
|
116
|
+
"@sanity/visual-editing": "1.8.4",
|
|
117
117
|
"@sanity/webhook": "4.0.2-bc",
|
|
118
|
-
"groq": "^3.19"
|
|
118
|
+
"groq": "^3.19",
|
|
119
|
+
"history": "^5.3.0"
|
|
119
120
|
},
|
|
120
121
|
"devDependencies": {
|
|
121
122
|
"@sanity/browserslist-config": "^1.0.3",
|
|
122
123
|
"@sanity/eslint-config-studio": "^3.0.1",
|
|
123
|
-
"@sanity/pkg-utils": "^5.1.
|
|
124
|
+
"@sanity/pkg-utils": "^5.1.4",
|
|
124
125
|
"@types/react": "^18.2.67",
|
|
125
126
|
"@typescript-eslint/eslint-plugin": "^7.3.1",
|
|
126
127
|
"@vitest/coverage-v8": "^1.4.0",
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import {memo} from 'react'
|
|
3
|
+
import {memo, useMemo} from 'react'
|
|
4
4
|
import {Studio, type StudioProps} from 'sanity'
|
|
5
5
|
|
|
6
|
+
import {createHashHistoryForStudio} from './createHashHistoryForStudio'
|
|
6
7
|
import {NextStudioLayout} from './NextStudioLayout'
|
|
7
8
|
import {NextStudioNoScript} from './NextStudioNoScript'
|
|
8
9
|
import {StyledComponentsRegistry} from './registry'
|
|
10
|
+
import {useIsMounted} from './useIsMounted'
|
|
9
11
|
|
|
10
12
|
/** @public */
|
|
11
13
|
export interface NextStudioProps extends StudioProps {
|
|
@@ -16,6 +18,13 @@ export interface NextStudioProps extends StudioProps {
|
|
|
16
18
|
* @alpha
|
|
17
19
|
*/
|
|
18
20
|
unstable__noScript?: boolean
|
|
21
|
+
/**
|
|
22
|
+
* The 'hash' option is new feature that is not yet stable for production, but is available for testing and its API won't change in a breaking way.
|
|
23
|
+
* If 'hash' doesn't work for you, or if you want to use a memory based history, you can use the `unstable_history` prop instead.
|
|
24
|
+
* @alpha
|
|
25
|
+
* @defaultValue 'browser'
|
|
26
|
+
*/
|
|
27
|
+
history?: 'browser' | 'hash'
|
|
19
28
|
}
|
|
20
29
|
/**
|
|
21
30
|
* Intended to render at the root of a page, letting the Studio own that page and render much like it would if you used `npx sanity start` to render
|
|
@@ -26,16 +35,37 @@ const NextStudioComponent = ({
|
|
|
26
35
|
config,
|
|
27
36
|
unstable__noScript = true,
|
|
28
37
|
scheme,
|
|
38
|
+
history,
|
|
29
39
|
...props
|
|
30
40
|
}: NextStudioProps) => {
|
|
41
|
+
const isMounted = useIsMounted()
|
|
42
|
+
const unstableHistory = useMemo<typeof props.unstable_history>(() => {
|
|
43
|
+
if (props.unstable_history && history) {
|
|
44
|
+
throw new Error('Cannot use both `unstable_history` and `history` props at the same time')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (isMounted && history === 'hash') {
|
|
48
|
+
return createHashHistoryForStudio()
|
|
49
|
+
}
|
|
50
|
+
return props.unstable_history
|
|
51
|
+
}, [history, isMounted, props.unstable_history])
|
|
52
|
+
|
|
31
53
|
return (
|
|
32
54
|
<>
|
|
33
55
|
{unstable__noScript && <NextStudioNoScript />}
|
|
34
|
-
<StyledComponentsRegistry>
|
|
56
|
+
<StyledComponentsRegistry isMounted={isMounted}>
|
|
35
57
|
<NextStudioLayout>
|
|
36
|
-
{
|
|
37
|
-
|
|
38
|
-
|
|
58
|
+
{history === 'hash' && !isMounted
|
|
59
|
+
? null
|
|
60
|
+
: children || (
|
|
61
|
+
<Studio
|
|
62
|
+
config={config}
|
|
63
|
+
scheme={scheme}
|
|
64
|
+
unstable_globalStyles
|
|
65
|
+
{...props}
|
|
66
|
+
unstable_history={unstableHistory}
|
|
67
|
+
/>
|
|
68
|
+
)}
|
|
39
69
|
</NextStudioLayout>
|
|
40
70
|
</StyledComponentsRegistry>
|
|
41
71
|
</>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {createHashHistory, type History, type Listener} from 'history'
|
|
2
|
+
|
|
3
|
+
/** @internal */
|
|
4
|
+
export function createHashHistoryForStudio(): History {
|
|
5
|
+
const history = createHashHistory()
|
|
6
|
+
return {
|
|
7
|
+
get action() {
|
|
8
|
+
return history.action
|
|
9
|
+
},
|
|
10
|
+
get location() {
|
|
11
|
+
return history.location
|
|
12
|
+
},
|
|
13
|
+
get createHref() {
|
|
14
|
+
return history.createHref
|
|
15
|
+
},
|
|
16
|
+
get push() {
|
|
17
|
+
return history.push
|
|
18
|
+
},
|
|
19
|
+
get replace() {
|
|
20
|
+
return history.replace
|
|
21
|
+
},
|
|
22
|
+
get go() {
|
|
23
|
+
return history.go
|
|
24
|
+
},
|
|
25
|
+
get back() {
|
|
26
|
+
return history.back
|
|
27
|
+
},
|
|
28
|
+
get forward() {
|
|
29
|
+
return history.forward
|
|
30
|
+
},
|
|
31
|
+
get block() {
|
|
32
|
+
return history.block
|
|
33
|
+
},
|
|
34
|
+
// Overriding listen to workaround a problem where native history provides history.listen(location => void), but the npm package is history.listen(({action, location}) => void)
|
|
35
|
+
listen(listener: Listener) {
|
|
36
|
+
// return history.listen(({ action, location }) => {
|
|
37
|
+
return history.listen(({location}) => {
|
|
38
|
+
// console.debug('history.listen', action, location)
|
|
39
|
+
// @ts-expect-error -- working around a bug? in studio
|
|
40
|
+
listener(location)
|
|
41
|
+
})
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/studio/registry.tsx
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
// https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components
|
|
2
2
|
import {useServerInsertedHTML} from 'next/navigation.js'
|
|
3
|
-
import {useState
|
|
3
|
+
import {useState} from 'react'
|
|
4
4
|
import {ServerStyleSheet, StyleSheetManager} from 'styled-components'
|
|
5
5
|
|
|
6
|
-
export function StyledComponentsRegistry({
|
|
6
|
+
export function StyledComponentsRegistry({
|
|
7
|
+
children,
|
|
8
|
+
isMounted,
|
|
9
|
+
}: {
|
|
10
|
+
children: React.ReactNode
|
|
11
|
+
isMounted: boolean
|
|
12
|
+
}): JSX.Element {
|
|
7
13
|
// Only create stylesheet once with lazy initial state
|
|
8
14
|
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
|
|
9
15
|
const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())
|
|
@@ -14,16 +20,9 @@ export function StyledComponentsRegistry({children}: {children: React.ReactNode}
|
|
|
14
20
|
return <>{styles}</>
|
|
15
21
|
})
|
|
16
22
|
|
|
17
|
-
const isMounted = useSyncExternalStore(
|
|
18
|
-
subscribe,
|
|
19
|
-
() => true,
|
|
20
|
-
() => false,
|
|
21
|
-
)
|
|
22
23
|
if (isMounted) return <>{children}</>
|
|
23
24
|
|
|
24
25
|
return (
|
|
25
26
|
<StyleSheetManager sheet={styledComponentsStyleSheet.instance}>{children}</StyleSheetManager>
|
|
26
27
|
)
|
|
27
28
|
}
|
|
28
|
-
// eslint-disable-next-line no-empty-function
|
|
29
|
-
const subscribe = () => () => {}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {useSyncExternalStore} from 'react'
|
|
2
|
+
|
|
3
|
+
/** @internal */
|
|
4
|
+
export function useIsMounted(): boolean {
|
|
5
|
+
return useSyncExternalStore(
|
|
6
|
+
emptySubscribe,
|
|
7
|
+
() => true,
|
|
8
|
+
() => false,
|
|
9
|
+
)
|
|
10
|
+
}
|
|
11
|
+
// eslint-disable-next-line no-empty-function
|
|
12
|
+
const emptySubscribe = () => () => {}
|