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

Ability to pass BootstrapOptions when bootstrapping standalone application #47538

Closed
edbzn opened this issue Sep 24, 2022 · 16 comments
Closed

Ability to pass BootstrapOptions when bootstrapping standalone application #47538

edbzn opened this issue Sep 24, 2022 · 16 comments
Labels
area: core Issues related to the framework runtime core: bootstrap cross-cutting: standalone Issues related to the NgModule-less world feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Milestone

Comments

@edbzn
Copy link
Contributor

edbzn commented Sep 24, 2022

Which @angular/* package(s) are relevant/related to the feature request?

platform-browser

Description

Hi there,

I started to convert a Zoneless application to standalone components, and I noticed it's not possible to bootstrap a standalone application without Zone.js, so I have to keep the AppModule to be able to pass the ngZone configuration at bootstrap.

platformBrowserDynamic()
  .bootstrapModule(AppModule, {
    ngZone: 'noop',
  });

Proposed solution

It would be nice to be able to pass the BootstrapOptions to the bootstrapApplication function like so:

bootstrapApplication(AppComponent, { ngZone: 'noop' })

Alternatives considered

N/A

@BioPhoton
Copy link
Contributor

Hi @edbzn and THX for opening this issue!

I tried a lot the last days to get it working...

One clean solution could be to use DI and override NgZone with θNgNoopZone.
The problem however is that boootstrapApplication has zone.js requirement hardcoded...

What is a ugly workaround is to provide zone.js in the bundle but flag all used API's so you don't actually patch them.
with this in addition to the θNgNoopZone approach it can work. But there is all the bootstrap improvements and bundle size gone
😢
I really hope this gets fixed soon as I see no real reason why... The module full approach also supports it.

Even if zone-less CD is an active topic I don't think everyone needs is to go standalone.

Happy to hear the teams opinion here. 🙏

@jessicajaniuk jessicajaniuk added the area: core Issues related to the framework runtime label Sep 26, 2022
@ngbot ngbot bot added this to the needsTriage milestone Sep 26, 2022
@alxhub alxhub added core: bootstrap bug cross-cutting: standalone Issues related to the NgModule-less world labels Sep 26, 2022
@alxhub
Copy link
Member

alxhub commented Sep 26, 2022

This was a deliberate choice we made when designing bootstrapApplication - we chose to create a minimal API that didn't carry over any of the options from the bootstrapModule API.

ngZone: 'noop' is what I would consider an advanced, low-level option. It's not something you can just set - using this option requires completely rethinking how state works in your application and how change detection is triggered.

For now, continue to use bootstrapModule if you require a zoneless application. Reactivity, Change Detection, and "zoneless" is an area of focus for us in 2023, so we hope to have a real story here at some point.

@alxhub alxhub closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2022
@MaximSagan
Copy link

MaximSagan commented Oct 18, 2022

@alxhub

ngZone: 'noop' may be advanced, but ngZoneEventCoalescing: true is supposedly an optimization to reduce change detection cycles. Users may switch this option on whether they have a low level understanding of ngZone or not, as was the case with my team. We are now hesitant to migrate our apps to be fully standalone component-based, because losing ngZoneEventCoalescing: true could potentially have adverse affects on our app's behavior.

FYI, as @BioPhoton suggested above, the following does not have the expected effect (although it does somehow manage to break Zone entirely...)

bootstrapApplication(AppComponent, {
    providers: [
        {
            provide: NgZone,
            useValue: new NgZone({ shouldCoalesceEventChangeDetection: false })
        },
    ]
});

@hiepxanh
Copy link
Contributor

@MaximSagan that good, I make it work with angular

@pkozlowski-opensource
Copy link
Member

zone.js event coalescing is a good use-case and the option we should support. I'm going to re-open this issue so we can adjust the API.

@hiepxanh
Copy link
Contributor

hiepxanh commented Oct 19, 2022

@pkozlowski-opensource thank you so much, that's very kind of you, after zoneless enable to work with standalone version, I can make my test with angular workable with vite

@AndrewKushnir AndrewKushnir added feature Issue that requests a new feature feature: under consideration Feature request for which voting has completed and the request is now under consideration and removed bug labels Oct 26, 2022
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Oct 26, 2022
@TicTak21
Copy link

Hello.
I would really like to see this feature available. Is there any progress in the discussion?

@hiepxanh
Copy link
Contributor

I think this feature is very important, it enable me to make angular work with Vite, please take a look <3

@hiepxanh
Copy link
Contributor

btw I think this PR is for this issue? #49079

@JeanMeche
Copy link
Member

Per Andrew Scott's comment in #49079, the team hasn't settled for an API yet but it seems in progress with the landing of the signal proposal.

@elgreco247
Copy link

This is fixed with #49557 (set coalescing options via provideZoneChangeDetection() and override NgZone implementation using DI => unsupported, but possible).

@pkozlowski-opensource
Copy link
Member

It is indeed, thnx @elgreco247

Fixed in #49557

@hiepxanh
Copy link
Contributor

@pkozlowski-opensource I think current fix is not the purpose of issue, the issue mean add: ngZone: 'noop' option to bootstrap option. the NgZoneOptions is not the one we expecting because it lack of ngZone: 'noop', or there is an other way to achive zoneless with standalone?

@hiepxanh
Copy link
Contributor

image
this is #47886 expecting, ngZone: 'noop' for standalone application

@elgreco247
Copy link

or there is an other way to achive zoneless with standalone?

@hiepxanh IIUC it is now possible using DI: {provide: NgZone, useClass: ɵNoopNgZone}; but it is not officially supported (hence the internal import).

@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 May 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime core: bootstrap cross-cutting: standalone Issues related to the NgModule-less world feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests