-
Notifications
You must be signed in to change notification settings - Fork 27k
fix(common): Don't run preconnect assertion on the server. #56213
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
Conversation
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'm wondering if we should just check if the current platform is server and exit in this case:
| if (!this.window || this.isServer) return; | |
| if (this.isServer) return; |
I think that was the intention of the window-based check.
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 kept it because this.window is typed as Window | null, should we change the typing ?
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.
Thanks for additional information. In this case we can move this check to the constructor:
if (!this.isServer && typeof win !== 'undefined') {
this.window = win;
}
So we set the window reference only when we are not on the server. What do you think?
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.
@JeanMeche, I understand you didn't originally work on this part, but there's an issue with how we're obtaining the base href, and it also highlights a couple of other issues.
- We're currently using the Window object, which is incorrect. Instead, we should be using the
PlatformLocationservice. This service will return the correct base when running on the server. When an absolute URL is provided, thePlatformLocationservice handles it correctly. - When a relative URL is provided in the server config, we're currently setting the base href to
/, which is not valid, as you pointed out. This setting lacks a protocol and makes thehrefinvalid.export function parseDocument(html: string, url = '/') {
Maybe the getURL function should be updated to use a base instead of a Window object:
export function getUrl(src: string, base: string): URLThis approach is essentially equivalent to using new URL(), because if src is absolute, new URL(src) yields the same result as new URL(src, win.location.href).
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.
@alan-agius4 quick question: the change is in this PR should make this service a noop on the server (only be invoked in a browser). Would you recommend changing the mentioned logic anyway?
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 agree that accessing the window global isn't great. I've refactored to use PlatformLocation.
c769731 to
758595c
Compare
alan-agius4
left a comment
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.
LGTM, couple of minor nits.
packages/common/src/directives/ng_optimized_image/lcp_image_observer.ts
Outdated
Show resolved
Hide resolved
packages/common/src/directives/ng_optimized_image/lcp_image_observer.ts
Outdated
Show resolved
Hide resolved
packages/common/src/directives/ng_optimized_image/lcp_image_observer.ts
Outdated
Show resolved
Hide resolved
|
Caretaker note: presubmit is "green" for the changes in this PR, this PR is ready for merge. |
|
This PR was merged into the repository by commit 39e48ce. The changes were merged into the following branches: main, 18.0.x |
…ngular#56213)" This reverts commit 39e48ce.
|
The change will be reverted via #56740, since there are some breakages in Google's codebase. The error looks like this: I think we may need to split this PR into 2:
|
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
The
windowglobal is patched by domino on the server but the value ofwindow.location.hrefisn't a valid base.Before this change
getUrl()would throw when running in devmode on the server.Fixes #56207