Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(elements): switch to ComponentRef.setInput & remove custom scheduler #56728

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion goldens/size-tracking/integration-payloads.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"platform-server-hydration/browser": {
"uncompressed": {
"main": 207890,
"main": 212989,
"polyfills": 33807,
"event-dispatch-contract.min": 476
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export const enum NotificationSource {
// above.
Listener,

// Custom elements do sometimes require checking directly.
CustomElement,

// The following notifications do not require views to be refreshed
// but we should execute render hooks:
// Render hooks are guaranteed to execute with the schedulers timing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ export class ChangeDetectionSchedulerImpl implements ChangeDetectionScheduler {
// to make listener callbacks work correctly with `OnPush` components.
return;
}

let force = false;

switch (source) {
case NotificationSource.MarkAncestorsForTraversal: {
this.appRef.dirtyFlags |= ApplicationRefDirtyFlags.ViewTreeTraversal;
Expand All @@ -142,6 +145,14 @@ export class ChangeDetectionSchedulerImpl implements ChangeDetectionScheduler {
this.appRef.deferredDirtyFlags |= ApplicationRefDirtyFlags.AfterRender;
break;
}
case NotificationSource.CustomElement: {
// We use `ViewTreeTraversal` to ensure we refresh the element even if this is triggered
// during CD. In practice this is a no-op since the elements code also calls via a
// `markForRefresh()` API which sends `NotificationSource.MarkAncestorsForTraversal` anyway.
this.appRef.dirtyFlags |= ApplicationRefDirtyFlags.ViewTreeTraversal;
force = true;
break;
}
case NotificationSource.ViewDetachedFromDOM:
case NotificationSource.ViewAttached:
case NotificationSource.RenderHook:
Expand All @@ -154,7 +165,7 @@ export class ChangeDetectionSchedulerImpl implements ChangeDetectionScheduler {
}
}

if (!this.shouldScheduleTick()) {
if (!this.shouldScheduleTick(force)) {
return;
}

Expand All @@ -180,8 +191,8 @@ export class ChangeDetectionSchedulerImpl implements ChangeDetectionScheduler {
}
}

private shouldScheduleTick(): boolean {
if (this.disableScheduling) {
private shouldScheduleTick(force: boolean): boolean {
if (this.disableScheduling && !force) {
return false;
}
// already scheduled or running
Expand Down
23 changes: 22 additions & 1 deletion packages/core/src/render3/view_ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
LView,
LViewFlags,
PARENT,
REACTIVE_TEMPLATE_CONSUMER,
TVIEW,
} from './interfaces/view';
import {
Expand All @@ -35,7 +36,11 @@ import {
trackMovedView,
} from './node_manipulation';
import {CheckNoChangesMode} from './state';
import {storeLViewOnDestroy, updateAncestorTraversalFlagsOnAttach} from './util/view_utils';
import {
markViewForRefresh,
storeLViewOnDestroy,
updateAncestorTraversalFlagsOnAttach,
} from './util/view_utils';

// Needed due to tsickle downleveling where multiple `implements` with classes creates
// multiple @extends in Closure annotations, which is illegal. This workaround fixes
Expand Down Expand Up @@ -80,6 +85,18 @@ export class ViewRef<T> implements EmbeddedViewRef<T>, ChangeDetectorRefInterfac
return this._lView[CONTEXT] as unknown as T;
}

/**
* Reports whether the given view is considered dirty according to the different marking mechanisms.
*/
get dirty(): boolean {
return (
!!(
this._lView[FLAGS] &
(LViewFlags.Dirty | LViewFlags.RefreshView | LViewFlags.HasChildViewsToRefresh)
) || !!this._lView[REACTIVE_TEMPLATE_CONSUMER]?.dirty
);
}

/**
* @deprecated Replacing the full context object is not supported. Modify the context
* directly, or consider using a `Proxy` if you need to replace the full object.
Expand Down Expand Up @@ -164,6 +181,10 @@ export class ViewRef<T> implements EmbeddedViewRef<T>, ChangeDetectorRefInterfac
markViewDirty(this._cdRefInjectingView || this._lView, NotificationSource.MarkForCheck);
}

markForRefresh(): void {
markViewForRefresh(this._cdRefInjectingView || this._lView);
}

/**
* Detaches the view from the change detection tree.
*
Expand Down
Loading