{{ message }}
feat: modernize CDK portal/dialog internals and drop ComponentFactoryResolver#171
Open
edusperoni wants to merge 5 commits into
Open
feat: modernize CDK portal/dialog internals and drop ComponentFactoryResolver#171edusperoni wants to merge 5 commits into
edusperoni wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/angular/src/lib/legacy/directives/dialogs.ts (1)
177-192: 💤 Low valueConsider removing unused
detachedLoaderRefparameter.The
detachedLoaderRefparameter is declared at line 120 but never assigned in_showDialog, so it will always beundefinedwhen passed to_handleFailedOpen. While the optional chaining (?.) operators handle this safely, the parameter is misleading and thedetectChanges()call on line 189 will never execute.♻️ Suggested simplification
- private _handleFailedOpen(modalParams: ModalDialogParams, portalOutlet?: NativeScriptDomPortalOutlet, detachedLoaderRef?: ComponentRef<DetachedLoader>): never { + private _handleFailedOpen(modalParams: ModalDialogParams, portalOutlet?: NativeScriptDomPortalOutlet): never { const index = this.openedModalParams?.indexOf(modalParams) ?? -1; if (index > -1) { this.openedModalParams.splice(index, 1); } this.location?._closeModalNavigation(); portalOutlet?.dispose(); - detachedLoaderRef?.instance.detectChanges(); - detachedLoaderRef?.destroy(); throw new Error('Failed to open dialog: the modal view could not be presented. This usually happens when another modal is already being presented.'); }And update the call site at line 172:
- this._handleFailedOpen(modalParams, portalOutlet, detachedLoaderRef); + this._handleFailedOpen(modalParams, portalOutlet);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/angular/src/lib/legacy/directives/dialogs.ts` around lines 177 - 192, The detachedLoaderRef parameter in the _handleFailedOpen method is never assigned a value in _showDialog and will always be undefined, making it misleading and causing the detectChanges() call to never execute. Remove the detachedLoaderRef parameter from the _handleFailedOpen method signature, remove the associated method calls (detachedLoaderRef?.instance.detectChanges() and detachedLoaderRef?.destroy()) that operate on it, and update the call site where _handleFailedOpen is invoked (around line 172) to no longer pass this parameter.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/angular/src/lib/legacy/directives/dialogs.ts`:
- Around line 177-192: The detachedLoaderRef parameter in the _handleFailedOpen
method is never assigned a value in _showDialog and will always be undefined,
making it misleading and causing the detectChanges() call to never execute.
Remove the detachedLoaderRef parameter from the _handleFailedOpen method
signature, remove the associated method calls
(detachedLoaderRef?.instance.detectChanges() and detachedLoaderRef?.destroy())
that operate on it, and update the call site where _handleFailedOpen is invoked
(around line 172) to no longer pass this parameter.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 26643213-ff61-453d-ba1b-3a1132172b50
📒 Files selected for processing (12)
apps/nativescript-demo-ng/src/tests/detached-utils-tests.spec.tspackages/angular/src/lib/cdk/detached-loader.tspackages/angular/src/lib/cdk/dialog/dialog-config.tspackages/angular/src/lib/cdk/dialog/dialog-services.tspackages/angular/src/lib/cdk/dialog/native-modal-ref.tspackages/angular/src/lib/cdk/portal/common.tspackages/angular/src/lib/cdk/portal/nsdom-portal-outlet.tspackages/angular/src/lib/cdk/portal/portal-directives.tspackages/angular/src/lib/detached-loader-utils.tspackages/angular/src/lib/legacy/directives/dialogs.tspackages/angular/src/lib/legacy/router/page-router-outlet.tspackages/angular/src/lib/utils/general.ts
e308fd0 to
b83e315
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

PR Checklist
What is the current behavior?
ApplicationRef.cdk/portalprimitives (Portal,ComponentPortal,TemplatePortal,CdkPortalOutlet,NativeScriptDomPortalOutlet) were based on an older revision of@angular/components. They lackedprojectableNodes/bindings/directivesonComponentPortal, the embedded-viewinjectoronTemplatePortal,ngModuleRef/EnvironmentInjectorresolution, and theApplicationRef.viewCountguard before detaching views.ComponentFactoryResolver/resolveComponentFactoryAPI in the portal outlet, detached loader, dialog config, legacy modal dialogs, and the page router outlet.What is the new behavior?
NativeModalRef(new dialog API) and the legacyModalDialogServicedetect a failedshowModalvia a newdidModalOpenhelper. Instead of silently failing, they roll back the modal navigation state, dispose the portal outlet / detached loader so nothing leaks, and throw a descriptive error ("Failed to open dialog: the modal view could not be presented...").@angular/components:ComponentPortalnow supportsprojectableNodes,bindings, anddirectives;TemplatePortalaccepts aninjector.CdkPortal/CdkPortalOutletmigrated toinject()-based DI and the@Inputgetter/setter form.NativeScriptDomPortalOutletresolvesngModuleRef/EnvironmentInjector, forwards the new portal options, guardsdetachViewwithviewCount, and tracks the attached portal.NativeDialogConfiggainedbindings, which are passed through to the rendered component; template dialogs now receive the dialog injector.ComponentFactoryResolverfrom the repo, migrating every usage tocreateComponent/ViewContainerRef.createComponent.PageRouterOutlet.activateWithnow matches Angular's currentRouterOutletContractsignature (EnvironmentInjector).Fixes/Implements/Closes #[Issue Number].
BREAKING CHANGES:
A failed dialog/modal open now throws instead of failing silently. Code that opens dialogs (
NativeDialog.open,ModalDialogService.showModal, and directNativeModalRefusage) may now throw if NativeScript cannot present the modal (commonly: trying to open a dialog while another is already being presented). Previously this returned/resolved without error.The deprecated
ComponentFactoryResolver-based public API surface was dropped:NativeScriptDomPortalOutletconstructor no longer accepts aComponentFactoryResolverargument.new NativeScriptDomPortalOutlet(view, resolver, appRef, injector)new NativeScriptDomPortalOutlet(view, appRef, injector)generateDetachedLoader(resolver, injector, viewContainerRef?)lost its firstresolverparameter.generateDetachedLoader(resolver, injector, vcRef)generateDetachedLoader(injector, vcRef)resolveroption was removed fromgenerateNativeScriptView(...)'s options object.NativeDialogConfig.componentFactoryResolverwas removed.Migration steps:
try/catch(or.catch()on the returned promise) and handle the error, instead of relying on the previous silent no-op.ComponentFactoryResolveryou were passing to the APIs above — Angular resolves components without it. Drop theresolverargument/option and thecomponentFactoryResolverconfig field; no replacement is required.Summary by CodeRabbit
Release Notes
New Features
bindingsoption for injecting dependencies into component-based dialogsBug Fixes
Refactor