refactor: extract isWebviewIframe helper to reduce duplication in service worker#315498
Closed
harshagarwalnyu wants to merge 2 commits into
Closed
refactor: extract isWebviewIframe helper to reduce duplication in service worker#315498harshagarwalnyu wants to merge 2 commits into
harshagarwalnyu wants to merge 2 commits into
Conversation
Author
|
Closing — the suggestion is already captured in the comment on #315495. @yongsooim can incorporate the change directly if useful. |
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the webview service worker client-resolution logic by extracting the repeated “is this a webview iframe entrypoint?” pathname check into a shared helper, reducing duplication in the worker/iframe matching flow.
Changes:
- Extract repeated webview iframe pathname matching into
isWebviewIframe(url). - Reuse
isWebviewIframeingetOuterIframeClientandgetWebviewIdForWorkerClientto keep entrypoint checks consistent. - Adjust resource/localhost request handling to resolve a missing
webviewIdfor worker/sharedworker clients viagetWebviewIdForWorkerClient.
Comment on lines
539
to
+545
| /** | ||
| * @param {string} webviewId | ||
| * @returns {Promise<Client[]>} | ||
| */ | ||
|
|
||
| /** | ||
| * @param {URL} url |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is a follow-up refactor complementing #315495.
What
Extracts the repeated webview iframe pathname check into a shared isWebviewIframe(url) helper:
js function isWebviewIframe(url) { return (url.pathname === ${rootPath}/ || url.pathname === ${rootPath}/index.html || url.pathname === ${rootPath}/index-no-csp.html); }Both getOuterIframeClient and getWebviewIdForWorkerClient (added in #315495) performed identical inline pathname checks. This extracts them into one place.
Why
The Copilot AI reviewer on #315495 flagged this duplication as a drift risk — if entry points change, both sites would need updating independently. This addresses that concern.
Relationship to #315495
This PR is stacked on top of #315495 and should only be merged after it. Happy to squash these into a single commit if the maintainers prefer, or @yongsooim is welcome to pull this change directly.