-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ref(core): Remove redundant iframe check in supportsNativeFetch
#19853
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
Open
HazAT
wants to merge
4
commits into
develop
Choose a base branch
from
bundle-size/supports-native-fetch
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+53
−56
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dff6335
refactor(core): Remove redundant iframe check in supportsNativeFetch
HazAT 0f3a8f0
move getNativeImplementation to core, rework supportsNativeFetch
Lms24 6ded375
try other approach, extract iframe implementation retrieval
Lms24 24e35f3
fix last issue?
Lms24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/core/src/utils/getNativeImplementationFromIframe.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { DEBUG_BUILD } from '../debug-build'; | ||
| import { GLOBAL_OBJ } from './worldwide'; | ||
| import { debug } from './debug-logger'; | ||
|
|
||
| const WINDOW = GLOBAL_OBJ as unknown as Window; | ||
|
|
||
| interface CacheableImplementations { | ||
| setTimeout: typeof WINDOW.setTimeout; | ||
| fetch: typeof WINDOW.fetch; | ||
| } | ||
|
|
||
| export function getNativeImplementationFromIframe<T extends keyof CacheableImplementations>(name: T) { | ||
| let impl = undefined; | ||
| const document = WINDOW.document; | ||
| // eslint-disable-next-line deprecation/deprecation | ||
| if (document && typeof document.createElement === 'function') { | ||
| try { | ||
| const sandbox = document.createElement('iframe'); | ||
| sandbox.hidden = true; | ||
| document.head.appendChild(sandbox); | ||
| const contentWindow = sandbox.contentWindow; | ||
| if (contentWindow?.[name]) { | ||
| impl = contentWindow[name] as CacheableImplementations[T]; | ||
| } | ||
| document.head.removeChild(sandbox); | ||
| } catch (e) { | ||
| // Could not create sandbox iframe, just use window.xxx | ||
| DEBUG_BUILD && debug.warn(`Could not create sandbox iframe for ${name} check, bailing to window.${name}: `, e); | ||
| } | ||
| } | ||
| return impl; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Fallback path no longer caches, causing repeated iframe creation
Medium Severity
When
getNativeImplementationFromIframereturnsundefined(e.g., CSP blocks iframe creation, or iframe'scontentWindowlacks the function),impl(WINDOW[name]) is returned without being stored incachedImplementations. Previously, the inline iframe code would fall through to the finalreturn (cachedImplementations[name] = impl.bind(WINDOW))line becauseimpl(the wrapped/polyfilled version fromWINDOW[name]) was still truthy. Now every subsequent call togetNativeImplementationwill re-attempt the iframe creation, since the cache is always empty. This particularly affectssetTimeout, which is called frequently fromreplay-internal(debounce, click handlers, etc.).Triggered by project rule: PR Review Guidelines for Cursor Bot