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

feat(@angular/ssr): introduce new hybrid rendering API #28139

Merged
merged 1 commit into from
Aug 9, 2024

Conversation

alan-agius4
Copy link
Collaborator

This commit introduces the new hybrid rendering API for Angular's Server-Side Rendering (SSR). The API aims to enhance the flexibility of SSR as discussed in angular/angular#56785

Notes

  • This API is currently not accessible.
  • The API shape is not final.
  • Additional work is required in the Angular CLI to:
    • Wire up the manifest.
    • Integrate other necessary components.

@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: @angular/ssr labels Jul 30, 2024
@alan-agius4 alan-agius4 added P4 A relatively minor issue that is not relevant to core functions target: minor This PR is targeted for the next minor release and removed P4 A relatively minor issue that is not relevant to core functions labels Jul 30, 2024
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jul 30, 2024
@alan-agius4 alan-agius4 marked this pull request as ready for review July 30, 2024 11:30
Copy link
Collaborator

@dgp1130 dgp1130 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together @alan-agius4! Really excited to see so much progress here.

I left a bunch of comments, but most of them are questions for my own understanding / clarifying edge case behavior. The rest are all relatively minor improvements to consider, so don't worry about them too much. Happy to chat and talk through some of the more complicated questions if that's easier.

I definitely appreciate the in depth JSDoc comments and tests, it really helps build up understanding of the change. 😁

@alan-agius4 alan-agius4 force-pushed the response-request-ssr branch 4 times, most recently from bfa27cc to 6aa7a2d Compare July 31, 2024 16:05
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed we should avoid Node-specific APIs as much as possible for maximum compatibility. I mainly just want to make sure that if we end up in a situation where we do need a Node API (maybe as a fallback, optimization, or other reason) we have a place to do that without breaking non-Node consumers.

Comment on lines +31 to +34
get hooks(): Hooks {
return AngularAppEngine.hooks;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question: since we store hooks as a static property on a class, do we invoke all of the hooks for all instances of a class?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, although there are no scenarios where multiple instances of AngularAppEngine should be created.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do end up with unit tests here (whether now or later), that would be a scenario where multiple AngularAppEngine objects are likely to be created.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, although there are no scenarios where multiple instances of AngularAppEngine should be created.

Would it be ok to store hooks on per-instance basis (vs having them as a static field)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, relying on instances would be brittle and prone to user errors. It depends on users exporting the instance with a predetermined name, whereas using a static field eliminates this need. Setting these hooks is crucial for the dev-server, as it requires access to them to add HMR and live-reload scripts.

*
* @example
* ```js
* const url = new URL('https://example.com/base/en/page');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question: is this the format of representing locale info that we have today (and we rely on) as well or it's a new format?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the existing format.

@alan-agius4 alan-agius4 force-pushed the response-request-ssr branch from 4a72050 to 29b1992 Compare August 5, 2024 13:12
Comment on lines +31 to +34
get hooks(): Hooks {
return AngularAppEngine.hooks;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, although there are no scenarios where multiple instances of AngularAppEngine should be created.

Would it be ok to store hooks on per-instance basis (vs having them as a static field)?

* @param value - The value to be checked.
* @returns True if the value is an Angular module (i.e., it has the `ɵmod` property), false otherwise.
*/
function isNgModule(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can potentially use the reflectComponentType public API here, which would return null for NgModules, see https://angular.dev/api/core/reflectComponentType?tab=usage-notes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think that reflectComponentType will work in this case because we do not have a component. What we need is a way to distinguish between a function that returns a promise and an NgModule.

@alan-agius4 alan-agius4 force-pushed the response-request-ssr branch 6 times, most recently from e323c37 to 5c21e85 Compare August 6, 2024 14:18
Copy link
Collaborator

@dgp1130 dgp1130 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for looking into the unit tests, I do think it helps a lot here.

Just a handful of minor suggestions, but nothing blocking or incredibly critical here.

@alan-agius4 alan-agius4 force-pushed the response-request-ssr branch 3 times, most recently from eb6d2d9 to 048c2f5 Compare August 7, 2024 09:15
Copy link

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

This commit introduces the new hybrid rendering API for Angular's Server-Side Rendering (SSR). The API aims to enhance the flexibility of SSR as discussed in angular/angular#56785

- This API is currently not accessible.
- Additional work is required in the Angular CLI to:
  - Wire up the manifest.
  - Integrate other necessary components.
@alan-agius4 alan-agius4 force-pushed the response-request-ssr branch from 048c2f5 to d9cb3a1 Compare August 9, 2024 07:12
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 9, 2024
@alan-agius4 alan-agius4 merged commit 3c9697a into angular:main Aug 9, 2024
31 checks passed
@alan-agius4 alan-agius4 deleted the response-request-ssr branch August 9, 2024 07:36
@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 Sep 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: @angular/ssr detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants