Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(next): nonce support (#3398)

Co-authored-by: Phil Pluckthun <phil@kitten.sh>

authored by

Adam Lane
Phil Pluckthun
and committed by
GitHub
423897f9 f66de5be

+17 -5
+5
.changeset/kind-trains-wink.md
··· 1 + --- 2 + '@urql/next': minor 3 + --- 4 + 5 + Support a `nonce` prop on `DataHydrationContextProvider` that passes it onto its script tags' attributes
+5 -3
packages/next-urql/src/DataHydrationContext.ts
··· 23 23 } 24 24 25 25 export const DataHydrationContextProvider = ({ 26 + nonce, 26 27 children, 27 - }: React.PropsWithChildren<{}>) => { 28 + }: React.PropsWithChildren<{ nonce?: string }>) => { 28 29 const dataHydrationContext = React.useRef<DataHydrationValue>(); 29 30 if (typeof window == 'undefined') { 30 31 if (!dataHydrationContext.current) 31 - dataHydrationContext.current = buildContext(); 32 + dataHydrationContext.current = buildContext({ nonce }); 32 33 } 33 34 34 35 return React.createElement( ··· 54 55 } 55 56 56 57 let key = 0; 57 - function buildContext(): DataHydrationValue { 58 + function buildContext({ nonce }: { nonce?: string }): DataHydrationValue { 58 59 const dataHydrationContext: DataHydrationValue = { 59 60 isInjecting: false, 60 61 operationValuesByKey: {}, ··· 71 72 72 73 return React.createElement('script', { 73 74 key: key++, 75 + nonce: nonce, 74 76 dangerouslySetInnerHTML: { __html }, 75 77 }); 76 78 },
+7 -2
packages/next-urql/src/Provider.ts
··· 47 47 children, 48 48 ssr, 49 49 client, 50 - }: React.PropsWithChildren<{ ssr: SSRExchange; client: Client }>) { 50 + nonce, 51 + }: React.PropsWithChildren<{ 52 + ssr: SSRExchange; 53 + client: Client; 54 + nonce?: string; 55 + }>) { 51 56 return React.createElement( 52 57 Provider, 53 58 { value: client }, 54 59 React.createElement( 55 60 SSRContext.Provider, 56 61 { value: ssr }, 57 - React.createElement(DataHydrationContextProvider, {}, children) 62 + React.createElement(DataHydrationContextProvider, { nonce }, children) 58 63 ) 59 64 ); 60 65 }