@@ -199,6 +199,19 @@ export type ExternalRuntimeScript = {
199199 src : string ,
200200 chunks : Array < Chunk | PrecomputedChunk > ,
201201} ;
202+
203+ /**
204+ * We normalize crossOrigin to be "use-credentials", "" or null.
205+ * Unless using "use-credentials" all the other strings behave like "anonymous" and "" is
206+ * shortest bytes-wise.
207+ */
208+ function getCrossOrigin ( options ?: mixed ) {
209+ return options == null || typeof options . crossOrigin !== 'string'
210+ ? null
211+ : options . crossOrigin === 'use-credentials'
212+ ? 'use-credentials'
213+ : '' ;
214+ }
202215// Allows us to keep track of what we've already written so we can refer back to it.
203216// if passed externalRuntimeConfig and the enableFizzExternalRuntime feature flag
204217// is set, the server will send instructions via data attributes (instead of inline scripts)
@@ -267,12 +280,7 @@ export function createResponseState(
267280 typeof scriptConfig === 'string' ? scriptConfig : scriptConfig . src ;
268281 const integrity =
269282 typeof scriptConfig === 'string' ? undefined : scriptConfig . integrity ;
270- const crossOrigin =
271- typeof scriptConfig === 'string' || scriptConfig . crossOrigin == null
272- ? undefined
273- : scriptConfig . crossOrigin === 'use-credentials'
274- ? 'use-credentials'
275- : '' ;
283+ const crossOrigin = getCrossOrigin ( scriptConfig ) ;
276284
277285 bootstrapChunks . push (
278286 startScriptSrc ,
@@ -306,12 +314,7 @@ export function createResponseState(
306314 typeof scriptConfig === 'string' ? scriptConfig : scriptConfig . src ;
307315 const integrity =
308316 typeof scriptConfig === 'string' ? undefined : scriptConfig . integrity ;
309- const crossOrigin =
310- typeof scriptConfig === 'string' || scriptConfig . crossOrigin == null
311- ? undefined
312- : scriptConfig . crossOrigin === 'use-credentials'
313- ? 'use-credentials'
314- : '' ;
317+ const crossOrigin = getCrossOrigin ( scriptConfig ) ;
315318
316319 bootstrapChunks . push (
317320 startModuleSrc ,
@@ -5085,12 +5088,7 @@ export function preconnect(href: string, options?: ?{crossOrigin?: string}) {
50855088 }
50865089
50875090 if ( typeof href === 'string' && href ) {
5088- const crossOrigin =
5089- options == null || typeof options . crossOrigin !== 'string'
5090- ? null
5091- : options . crossOrigin === 'use-credentials'
5092- ? 'use-credentials'
5093- : '' ;
5091+ const crossOrigin = getCrossOrigin ( options ) ;
50945092
50955093 const key = `[preconnect][${
50965094 crossOrigin === null ? 'null' : crossOrigin
0 commit comments