-
Notifications
You must be signed in to change notification settings - Fork 47k
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 support for 'crossorigin' attribute on bootstrapScripts and bootstrapModules #26844
Conversation
const crossOrigin = | ||
typeof scriptConfig === 'string' ? undefined : scriptConfig.crossOrigin; |
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.
For crossorigin we have normalized this to "use-credentials" | "" | null
because unless you are using use-credentials all string values behave identically to "anonymous" and "" is the shortest bytes-wise.
@@ -282,6 +286,12 @@ export function createResponseState( | |||
stringToChunk(escapeTextForBrowser(integrity)), | |||
); | |||
} | |||
if (crossOrigin) { |
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.
This would fail for crossOrigin: ""
. Should be something like if (typeof crossOrigin === 'string')
* shortest bytes-wise. | ||
*/ | ||
function getCrossOrigin(options?: mixed) { | ||
return options == null || typeof options.crossOrigin !== 'string' |
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 overall nested ternary expressions require more mental overhead to reason about or to edit in the future..
if (options == null || typeof options.crossOrigin !== 'string') {
return null;
}
if (options.crossOrigin === 'use-credentials') {
return 'use-credentials';
}
return '';
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.
Sorry it took so long to follow up. I think this is close, feel free to @ me If I don't respond within a couple days of your next updates.
Thanks for submitting this PR, I really appreciate it :)
* Unless using "use-credentials" all the other strings behave like "anonymous" and "" is | ||
* shortest bytes-wise. | ||
*/ | ||
function getCrossOrigin(options?: mixed) { |
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'd revert the commit where you extract this function and leave it inline.
It works today that the script desciptors and the preconnect options happen to correlate and so this function works but it's essentially duck-typing a mixed object that provides no guarantees it will continue to stay in the shape it currently is in.
We'd hope closure would also inline these functions anyway and the logic isn't particularly complicated so we should just leave them inline
A compromise might be to only extract the function
function getCrossOriginFromString(crossOriginString: string): string {
return crossOriginString === 'use-credentials' ? crossOriginString : ""
}
and then just use it once you've checked that the cross origin config is known to not be null. closure will almost certainly inline this and it does not presume any particular shape of options/configuration
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.
Sure! Let me do this.
e5b91a4
to
08774cc
Compare
@gnoff reverted the commit. The |
This PR updates the vendored react dependencies using `pnpm sync-react` ### React upstream changes - facebook/react#27028 - facebook/react#27027 - facebook/react#27019 - facebook/react#26954 - facebook/react#26987 - facebook/react#26985 - facebook/react#26933 - facebook/react#26625 - facebook/react#27011 - facebook/react#27008 - facebook/react#26997 - facebook/react#26989 - facebook/react#26955 - facebook/react#26963 - facebook/react#26983 - facebook/react#26914 - facebook/react#26951 - facebook/react#26977 - facebook/react#26958 - facebook/react#26940 - facebook/react#26939 - facebook/react#26887 - facebook/react#26947 - facebook/react#26945 - facebook/react#26942 - facebook/react#26938 - facebook/react#26844 - facebook/react#25510 - facebook/react#26932 - facebook/react#26896 - facebook/react#26913 - facebook/react#26888 - facebook/react#26827 - facebook/react#26889 - facebook/react#26877 - facebook/react#26873 - facebook/react#26880 - facebook/react#26842 - facebook/react#26858 - facebook/react#26754 - facebook/react#26753 - facebook/react#26881 ### Related Closes #49409 (by facebook/react#26977) fix NEXT-1189 Co-authored-by: Shu Ding <g@shud.in>
Fixes #49409 ### React upstream changes - facebook/react#27045 - facebook/react#27051 - facebook/react#27032 - facebook/react#27031 - facebook/react#27029 - facebook/react#27028 - facebook/react#27027 - facebook/react#27019 - facebook/react#26954 - facebook/react#26987 - facebook/react#26985 - facebook/react#26933 - facebook/react#26625 - facebook/react#27011 - facebook/react#27008 - facebook/react#26997 - facebook/react#26989 - facebook/react#26955 - facebook/react#26963 - facebook/react#26983 - facebook/react#26914 - facebook/react#26951 - facebook/react#26977 - facebook/react#26958 - facebook/react#26940 - facebook/react#26939 - facebook/react#26887 - facebook/react#26947 - facebook/react#26945 - facebook/react#26942 - facebook/react#26938 - facebook/react#26844 - facebook/react#25510 - facebook/react#26932 - facebook/react#26896 - facebook/react#26913 - facebook/react#26888 - facebook/react#26827 - facebook/react#26889 - facebook/react#26877 - facebook/react#26873 - facebook/react#26880 - facebook/react#26842 - facebook/react#26858 - facebook/react#26754 - facebook/react#26753 - facebook/react#26881 --------- Co-authored-by: Jiachi Liu <inbox@huozhi.im>
This PR updates the vendored react dependencies using `pnpm sync-react` ### React upstream changes - facebook/react#27028 - facebook/react#27027 - facebook/react#27019 - facebook/react#26954 - facebook/react#26987 - facebook/react#26985 - facebook/react#26933 - facebook/react#26625 - facebook/react#27011 - facebook/react#27008 - facebook/react#26997 - facebook/react#26989 - facebook/react#26955 - facebook/react#26963 - facebook/react#26983 - facebook/react#26914 - facebook/react#26951 - facebook/react#26977 - facebook/react#26958 - facebook/react#26940 - facebook/react#26939 - facebook/react#26887 - facebook/react#26947 - facebook/react#26945 - facebook/react#26942 - facebook/react#26938 - facebook/react#26844 - facebook/react#25510 - facebook/react#26932 - facebook/react#26896 - facebook/react#26913 - facebook/react#26888 - facebook/react#26827 - facebook/react#26889 - facebook/react#26877 - facebook/react#26873 - facebook/react#26880 - facebook/react#26842 - facebook/react#26858 - facebook/react#26754 - facebook/react#26753 - facebook/react#26881 ### Related Closes #49409 (by facebook/react#26977) fix NEXT-1189 Co-authored-by: Shu Ding <g@shud.in>
…trapModules (facebook#26844) base build ci job failing but this change is unrelated and I think it is just flake with the builds host application
…s and bootstrap modules (facebook#26942) The recently merged support for crossorigin in bootstrap scripts did not implement the functionality for preloading. This adds it see facebook#26844
Summary
When using window.onerror in the bootstrap script that is hosted in a CDN the error message will show "Script error." instead of a proper error message. This is because of the cross-origin script.
Use
crossOrigin
naming convention, following the same name used in other configurations like preinit and preconnectFixes #25989
How did you test this change?
Used
yarn test
and added tests for the new config making sure that script tag has thecrossorigin
attribute