-
Notifications
You must be signed in to change notification settings - Fork 46.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to load Fizz runtime from external file #25499
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import { | |
enableFilterEmptyStringAttributesDOM, | ||
enableCustomElementPropertySupport, | ||
enableFloat, | ||
enableFizzExternalRuntime, | ||
} from 'shared/ReactFeatureFlags'; | ||
|
||
import type { | ||
|
@@ -156,6 +157,7 @@ export function createResponseState( | |
bootstrapScriptContent: string | void, | ||
bootstrapScripts: $ReadOnlyArray<string | BootstrapScriptDescriptor> | void, | ||
bootstrapModules: $ReadOnlyArray<string | BootstrapScriptDescriptor> | void, | ||
externalRuntimeConfig: string | BootstrapScriptDescriptor | void, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style / naming - would it make sense to name something this like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, I'll defer to @gnoff and @sebmarkbage on the API shape. My best guess was to copy the convention for the other options, since it makes sense to me that they would be consistent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the I would probably just rename it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, we prefer few objects for perf. |
||
): ResponseState { | ||
const idPrefix = identifierPrefix === undefined ? '' : identifierPrefix; | ||
const inlineScriptWithNonce = | ||
|
@@ -172,6 +174,29 @@ export function createResponseState( | |
endInlineScript, | ||
); | ||
} | ||
if (enableFizzExternalRuntime) { | ||
if (externalRuntimeConfig !== undefined) { | ||
const src = | ||
typeof externalRuntimeConfig === 'string' | ||
? externalRuntimeConfig | ||
: externalRuntimeConfig.src; | ||
const integrity = | ||
typeof externalRuntimeConfig === 'string' | ||
? undefined | ||
: externalRuntimeConfig.integrity; | ||
bootstrapChunks.push( | ||
startScriptSrc, | ||
stringToChunk(escapeTextForBrowser(src)), | ||
); | ||
if (integrity) { | ||
bootstrapChunks.push( | ||
scriptIntegirty, | ||
stringToChunk(escapeTextForBrowser(integrity)), | ||
); | ||
} | ||
bootstrapChunks.push(endAsyncScript); | ||
Comment on lines
+187
to
+197
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will cause the runtime to emit after all the content. The right priority is probably much higher. I just merged support for scripts but we probably want to special case this one as the highest priority script to flush. I'm mostly just flagging it here not so that it gets changed in this PR but that I follow up in my own PR afterwards There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I can reorder it if you want. Or leave it for you to change. |
||
} | ||
} | ||
if (bootstrapScripts !== undefined) { | ||
for (let i = 0; i < bootstrapScripts.length; i++) { | ||
const scriptConfig = bootstrapScripts[i]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,7 @@ export const enableFloat = false; | |
export const enableHostSingletons = false; | ||
|
||
export const useModernStrictMode = false; | ||
export const enableFizzExternalRuntime = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is dead code tbh. I don't think we use it anywhere in www. It's a vestige from when we momentarily thought we would provide a special testing build of React. Need to delete, just haven't yet. |
||
|
||
// Flow magic to verify the exports of this file match the original version. | ||
((((null: any): ExportsType): FeatureFlagsType): ExportsType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to support the same configuration options as bootstrapScripts?