Skip to content
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

TEST - feat(platform-server): expose method for shimming global env #40544

Closed

Conversation

gkalpak
Copy link
Member

@gkalpak gkalpak commented Jan 23, 2021

WIP

@google-cla google-cla bot added the cla: yes label Jan 23, 2021
@gkalpak gkalpak changed the title TEST - fix(platform-server): shim global sooner TEST - feat(platform-server): expose method for shimming global env Jan 24, 2021
@mary-poppins
Copy link

You can preview 468cefa at https://pr40544-468cefa.ngbuilds.io/.

@gkalpak gkalpak force-pushed the fix-platform-server-load-domino branch from 468cefa to 14b9807 Compare January 24, 2021 17:25
@mary-poppins
Copy link

You can preview 14b9807 at https://pr40544-14b9807.ngbuilds.io/.

@gkalpak gkalpak force-pushed the fix-platform-server-load-domino branch from 14b9807 to f27da00 Compare January 25, 2021 14:32
@mary-poppins
Copy link

You can preview f27da00 at https://pr40544-f27da00.ngbuilds.io/.

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 witll be fixed in a subsequent commit.
@gkalpak gkalpak force-pushed the fix-platform-server-load-domino branch 2 times, most recently from 3fec49d to 27cddb5 Compare January 25, 2021 15:34
@mary-poppins
Copy link

You can preview 27cddb5 at https://pr40544-27cddb5.ngbuilds.io/.

`@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 an
side-effect-ful entry-point (`@angular/platform-server/shims`), 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
@gkalpak gkalpak force-pushed the fix-platform-server-load-domino branch from 27cddb5 to a9d33e8 Compare January 25, 2021 16:59
@gkalpak gkalpak closed this Jan 25, 2021
@gkalpak
Copy link
Member Author

gkalpak commented Jan 25, 2021

Superceded by #40559.

@mary-poppins
Copy link

You can preview a9d33e8 at https://pr40544-a9d33e8.ngbuilds.io/.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants