-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
fix(http): force macro task creation during request #49546
Conversation
8bd7c3b
to
0814906
Compare
0814906
to
9fa49a0
Compare
9fa49a0
to
d83f94d
Compare
//cc @AndrewKushnir, not sure if you want to review this, as we discussed about this a bit yesterday. |
4f02e42
to
d83f94d
Compare
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 looks great 👍
We'd probably need a TGP for this change.
@@ -320,3 +337,20 @@ export class HttpXhrBackend implements HttpBackend { | |||
}); | |||
} | |||
} | |||
|
|||
const MAX_INT = 2147483647; |
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.
Can we use Number.MAX_VALUE here? If not, could you plz add a comment into the code, so we have this context in the future.
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.
Added comment why.
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.
What about Number.MAX_SAFE_INTEGER
? That's basically what it is for, right?
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.
No, Number.MAX_SAFE_INTEGER
is a 53 bit integer.
@Injectable() | ||
export class ServerXhr implements XhrFactory { | ||
build(): XMLHttpRequest { | ||
return new xhr2.XMLHttpRequest(); | ||
} | ||
} | ||
|
||
export abstract class ZoneMacroTaskWrapper<S, R> { |
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.
Love the removal of this code (in favor of a more simple solution!) 👍
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.
reviewed-for: fw-http, fw-platform-server, integration-tests, public-api
This commit adds a background macrotask when an XHR request is performed. The macrotask is started during `loadstart` and ended during `loadend` event. The macrotask is needed so that the application is not stabilized during HTTP calls. This is important for server rendering, as the application is rendering when the application is stabilized. The application is stabilized when there are no longer pending Macro and Micro tasks intercepted by Zone.js, Since an XHR request is none of these, we create a background macrotask so that Zone.js is made aware that there is something pending. Prior to this change, we patched the `HttpHandler` in `@angular/platform-server` but this is not enough, as there can be multiple `HttpHandler` in an application, example when importing `HttpClient` in a lazy loaded component/module. Which causes a new unpatched instance of `HttpHandler` to be created in the child injector which is not intercepted by Zone.js and thus the application is stabalized and rendered before the XHR request is finalized. NB: Zone.js is fundamental for SSR and currently, it's not possible to do SSR without it. Closes: angular#49425
These two options where created for a feature which was never completed. angular/universal#1860 Eventually these options should be added to `withTransferCache` HTTP logic. DEPRECATED: `PlatformConfig.baseUrl` and `PlatformConfig.useAbsoluteUrl` platform-server config options are deprecated as these were not used.
c5e2257
to
b896849
Compare
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.
Reviewed-for: public-api
This PR was merged into the repository by commit e994608. |
…49546) These two options where created for a feature which was never completed. angular/universal#1860 Eventually these options should be added to `withTransferCache` HTTP logic. DEPRECATED: `PlatformConfig.baseUrl` and `PlatformConfig.useAbsoluteUrl` platform-server config options are deprecated as these were not used. PR Close #49546
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. |
refactor(platform-server): deprecate
useAbsoluteUrl
andbaseUrl
These two options where created for a feature which was never completed. angular/universal#1860
Eventually these options should be added to
withTransferCache
HTTP logic.DEPRECATED:
PlatformConfig.baseUrl
andPlatformConfig.useAbsoluteUrl
platform-server config options are deprecated as these were not used.fix(http): force macro task creation during HTTP request
This commit adds a background macrotask when an XHR request is performed. The macrotask is started during
loadstart
and ended duringloadend
event.The macrotask is needed so that the application is not stabilized during HTTP calls. This is important for server rendering, as the application is rendering when the application is stabilized.
The application is stabilized when there are no longer pending Macro and Micro tasks intercepted by Zone.js, Since an XHR request is none of these, we create a background macrotask so that Zone.js is
made aware that there is something pending.
Prior to this change, we patched the
HttpHandler
in@angular/platform-server
but this is not enough, as there can be multipleHttpHandler
in an application, example when importingHttpClient
in a lazy loaded component/module.Which causes a new unpatched instance of
HttpHandler
to be created in the child injector which is not intercepted by Zone.js and thus the application is stabalized and rendered before the XHR request is finalized.NB: Zone.js is fundamental for SSR and currently, it's not possible to do SSR without it.
Closes: #49425