-
Notifications
You must be signed in to change notification settings - Fork 25.4k
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
feat(platform-server): allow shimming the global env sooner #40559
Conversation
a9d33e8
to
5aae56d
Compare
You can preview 5aae56d at https://pr40559-5aae56d.ngbuilds.io/. |
…platform-server` shims In angular/angular#40559, a new `@angular/platform-server/shims` entry-point was introduced, which can be used to shim the server environment with APIs normally provided by the browser (such as DOM globals). If the project is using a version of Angular (and thus `@angular/platform-server`) that is known to include this new entry-point, the newly generated `main.server.ts` file should import it at the top in order to ensure that the shims will be available as soon as possible (before other direct or transitive imports that may rely on them). See also angular/angular#40559 for more details. NOTE: This `universal` schematic is the base for `app-shell`, `@nguniversal/express-engine` and `@nguniversal/hapi-engine`.
5aae56d
to
6340fd7
Compare
You can preview 6340fd7 at https://pr40559-6340fd7.ngbuilds.io/. |
6340fd7
to
f601f3f
Compare
You can preview f601f3f at https://pr40559-f601f3f.ngbuilds.io/. |
f601f3f
to
e8626aa
Compare
You can preview e8626aa at https://pr40559-e8626aa.ngbuilds.io/. |
I have updated the example to not use |
You can preview 5392175 at https://pr40559-5392175.ngbuilds.io/. |
Comments addressed (the main change is renaming the entry-point from |
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
reviewed-for: public-api
…#40737) Previously, if an entry-point had no public exports (such as the `@angular/platform-server/shims` introduced in #40559, which is a side-effect-ful entry-point), it was incorrectly marked as having all its exports deprecated (which marks the entry-point as deprecated as well). This commit fixes this by ensuring that an entry-point is not marked as having all its exports deprecated if it has no public exports. PR Close #40737
…#40737) Previously, if an entry-point had no public exports (such as the `@angular/platform-server/shims` introduced in #40559, which is a side-effect-ful entry-point), it was incorrectly marked as having all its exports deprecated (which marks the entry-point as deprecated as well). This commit fixes this by ensuring that an entry-point is not marked as having all its exports deprecated if it has no public exports. PR Close #40737
…#40737) Previously, if an entry-point had no public exports (such as the `@angular/platform-server/shims` introduced in #40559, which is a side-effect-ful entry-point), it was incorrectly marked as having all its exports deprecated (which marks the entry-point as deprecated as well). This commit fixes this by ensuring that an entry-point is not marked as having all its exports deprecated if it has no public exports. PR Close #40737
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
Reviewed-for: public-api
The `platform-server` package currently depends on the [domino][1] package. This commit adds `domino` to the list of dependencies for the `platform-server` `ng_module` target. [1]: https://www.npmjs.com/package/domino
This commit adds an integration test that uses `@angular/elements` with `@angular/platform-server` in order to highlight a current incompatibility. The issue will be fixed in a subsequent commit.
`@angular/platform-server` provides the foundation for rendering an Angular app on the server. In order to achieve that, it uses a server-side DOM implementation (currently [domino][1]). For rendering on the server to work as closely as possible to running the app on the browser, we need to make DOM globals (such as `Element`, `HTMLElement`, etc.), which are normally provided by the browser, available as globals on the server as well. Currently, `@angular/platform-server` achieves this by extending the `global` object with the DOM implementation provided by `domino`. This assignment happens in the [setDomTypes()][2] function, which is [called in a `PLATFORM_INITIALIZER`][3]. While this works in most cases, there are some scenarios where the DOM globals are needed sooner (i.e. before initializing the platform). See, for example, angular#24551 and angular#39950 for more details on such issues. This commit provides a way to solve this problem by exposing a side-effect-ful entry-point (`@angular/platform-server/init`), that shims the `global` object with DOM globals. People will be able to import this entry-point in their server-rendered apps before bootstrapping the app (for example, in their `main.server.ts` file). (See also [angular#39950 (comment)][4].) In a future update, the [`universal` schematics][5] will include such an import by default in newly generated projects. [1]: https://www.npmjs.com/package/domino [2]: https://github.com/angular/angular/blob/0fc8466f1be392917e0c/packages/platform-server/src/domino_adapter.ts#L17-L21 [3]: https://github.com/angular/angular/blob/0fc8466f1be392917e0c/packages/platform-server/src/server.ts#L33 [4]: angular#39950 (comment) [5]: https://github.com/angular/angular-cli/blob/cc51432661eb4ab4b6a3/packages/schematics/angular/universal
5392175
to
a67a720
Compare
You can preview a67a720 at https://pr40559-a67a720.ngbuilds.io/. |
This commit adds an integration test that uses `@angular/elements` with `@angular/platform-server` in order to highlight a current incompatibility. The issue will be fixed in a subsequent commit. PR Close #40559
`@angular/platform-server` provides the foundation for rendering an Angular app on the server. In order to achieve that, it uses a server-side DOM implementation (currently [domino][1]). For rendering on the server to work as closely as possible to running the app on the browser, we need to make DOM globals (such as `Element`, `HTMLElement`, etc.), which are normally provided by the browser, available as globals on the server as well. Currently, `@angular/platform-server` achieves this by extending the `global` object with the DOM implementation provided by `domino`. This assignment happens in the [setDomTypes()][2] function, which is [called in a `PLATFORM_INITIALIZER`][3]. While this works in most cases, there are some scenarios where the DOM globals are needed sooner (i.e. before initializing the platform). See, for example, #24551 and #39950 for more details on such issues. This commit provides a way to solve this problem by exposing a side-effect-ful entry-point (`@angular/platform-server/init`), that shims the `global` object with DOM globals. People will be able to import this entry-point in their server-rendered apps before bootstrapping the app (for example, in their `main.server.ts` file). (See also [#39950 (comment)][4].) In a future update, the [`universal` schematics][5] will include such an import by default in newly generated projects. [1]: https://www.npmjs.com/package/domino [2]: https://github.com/angular/angular/blob/0fc8466f1be392917e0c/packages/platform-server/src/domino_adapter.ts#L17-L21 [3]: https://github.com/angular/angular/blob/0fc8466f1be392917e0c/packages/platform-server/src/server.ts#L33 [4]: #39950 (comment) [5]: https://github.com/angular/angular-cli/blob/cc51432661eb4ab4b6a3/packages/schematics/angular/universal PR Close #40559
…platform-server` shims In angular/angular#40559, a new `@angular/platform-server/init` entry-point was introduced, which can be used to initialize the server environment by providing shims for APIs normally provided by the browser (such as DOM globals). If the project is using a version of Angular (and thus `@angular/platform-server`) that is known to include this new entry-point, the newly generated `main.server.ts` file should import it at the top in order to ensure that the shims will be available as soon as possible (before other direct or transitive imports that may rely on them). See also angular/angular#40559 for more details. NOTE: This `universal` schematic is the base for `app-shell`, `@nguniversal/express-engine` and `@nguniversal/hapi-engine`. Fixes angular/angular#40559
…platform-server` shims In angular/angular#40559, a new `@angular/platform-server/init` entry-point was introduced, which can be used to initialize the server environment by providing shims for APIs normally provided by the browser (such as DOM globals). If the project is using a version of Angular (and thus `@angular/platform-server`) that is known to include this new entry-point, the newly generated `main.server.ts` file should import it at the top in order to ensure that the shims will be available as soon as possible (before other direct or transitive imports that may rely on them). See also angular/angular#40559 for more details. NOTE: This `universal` schematic is the base for `app-shell`, `@nguniversal/express-engine` and `@nguniversal/hapi-engine`. Fixes angular/angular#40559
…platform-server` shims In angular/angular#40559, a new `@angular/platform-server/init` entry-point was introduced, which can be used to initialize the server environment by providing shims for APIs normally provided by the browser (such as DOM globals). If the project is using a version of Angular (and thus `@angular/platform-server`) that is known to include this new entry-point, the newly generated `main.server.ts` file should import it at the top in order to ensure that the shims will be available as soon as possible (before other direct or transitive imports that may rely on them). See also angular/angular#40559 for more details. NOTE: This `universal` schematic is the base for `app-shell`, `@nguniversal/express-engine` and `@nguniversal/hapi-engine`. Fixes angular/angular#40559
…platform-server` shims In angular/angular#40559, a new `@angular/platform-server/init` entry-point was introduced, which can be used to initialize the server environment by providing shims for APIs normally provided by the browser (such as DOM globals). If the project is using a version of Angular (and thus `@angular/platform-server`) that is known to include this new entry-point, the newly generated `main.server.ts` file should import it at the top in order to ensure that the shims will be available as soon as possible (before other direct or transitive imports that may rely on them). See also angular/angular#40559 for more details. NOTE: This `universal` schematic is the base for `app-shell`, `@nguniversal/express-engine` and `@nguniversal/hapi-engine`. Fixes angular/angular#40559
…platform-server` shims In angular/angular#40559, a new `@angular/platform-server/init` entry-point was introduced, which can be used to initialize the server environment by providing shims for APIs normally provided by the browser (such as DOM globals). If the project is using a version of Angular (and thus `@angular/platform-server`) that is known to include this new entry-point, the newly generated `main.server.ts` file should import it at the top in order to ensure that the shims will be available as soon as possible (before other direct or transitive imports that may rely on them). See also angular/angular#40559 for more details. NOTE: This `universal` schematic is the base for `app-shell`, `@nguniversal/express-engine` and `@nguniversal/hapi-engine`. Fixes angular/angular#40559
…platform-server` shims In angular/angular#40559, a new `@angular/platform-server/init` entry-point was introduced, which can be used to initialize the server environment by providing shims for APIs normally provided by the browser (such as DOM globals). If the project is using a version of Angular (and thus `@angular/platform-server`) that is known to include this new entry-point, the newly generated `main.server.ts` file should import it at the top in order to ensure that the shims will be available as soon as possible (before other direct or transitive imports that may rely on them). See also angular/angular#40559 for more details. NOTE: This `universal` schematic is the base for `app-shell`, `@nguniversal/express-engine` and `@nguniversal/hapi-engine`. Fixes angular/angular#40559
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. |
@angular/platform-server
provides the foundation for rendering an Angular app on the server. In order to achieve that, it uses a server-side DOM implementation (currently domino).For rendering on the server to work as closely as possible to running the app on the browser, we need to make DOM globals (such as
Element
,HTMLElement
, etc.), which are normally provided by the browser, available as globals on the server as well.Currently,
@angular/platform-server
achieves this by extending theglobal
object with the DOM implementation provided bydomino
. This assignment happens in the setDomTypes() function, which is called in aPLATFORM_INITIALIZER
. While this works in most cases, there are some scenarios where the DOM globals are needed sooner (i.e. before initializing the platform). See, for example, #24551 and #39950 for more details on such issues.This commit provides a way to solve this problem by exposing an side-effect-ful entry-point (
@angular/platform-server/shims
), that shims theglobal
object with DOM globals. People will be able to import this entry-point in their server-rendered apps before bootstrapping the app (for example, in theirmain.server.ts
file).(See also #39950 (comment).)
In a future update, the
universal
schematics will include such an import by default in newly generated projects.Closes #39950.
Related to angular/angular-cli#19869.