MCPcopy Index your code
hub / github.com/angular/angular / withEventReplay

Function withEventReplay

packages/core/src/hydration/event_replay.ts:76–202  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

74 *
75 */
76export function withEventReplay(): Provider[] {
77 const providers: Provider[] = [
78 {
79 provide: IS_EVENT_REPLAY_ENABLED,
80 useFactory: () => {
81 let isEnabled = true;
82 if (typeof ngServerMode === 'undefined' || !ngServerMode) {
83 // Note: globalThis[CONTRACT_PROPERTY] may be undefined in case Event Replay feature
84 // is enabled, but there are no events configured in this application, in which case
85 // we don't activate this feature, since there are no events to replay.
86 const appId = inject(APP_ID);
87 isEnabled = !!window._ejsas?.[appId];
88 }
89 if (isEnabled) {
90 performanceMarkFeature('NgEventReplay');
91 }
92 return isEnabled;
93 },
94 },
95 ];
96
97 if (typeof ngServerMode === 'undefined' || !ngServerMode) {
98 providers.push(
99 {
100 provide: ENVIRONMENT_INITIALIZER,
101 useValue: () => {
102 const appRef = inject(ApplicationRef);
103 const {injector} = appRef;
104 // We have to check for the appRef here due to the possibility of multiple apps
105 // being present on the same page. We only want to enable event replay for the
106 // apps that actually want it.
107 if (!appsWithEventReplay.has(appRef)) {
108 const jsActionMap = inject(JSACTION_BLOCK_ELEMENT_MAP);
109 if (shouldEnableEventReplay(injector)) {
110 enableStashEventListenerImpl();
111 const appId = injector.get(APP_ID);
112 const clearStashFn = setStashFn(
113 appId,
114 (rEl: RNode, eventName: string, listenerFn: VoidFunction) => {
115 // If a user binds to a ng-container and uses a directive that binds using a host listener,
116 // this element could be a comment node. So we need to ensure we have an actual element
117 // node before stashing anything.
118 if ((rEl as Node).nodeType !== Node.ELEMENT_NODE) return;
119 sharedStashFunction(rEl as RElement, eventName, listenerFn);
120 sharedMapFunction(rEl as RElement, jsActionMap);
121 },
122 );
123 // Clean up the reference to the function set by the environment initializer,
124 // as the function closure may capture injected elements and prevent them
125 // from being properly garbage collected.
126 appRef.onDestroy(clearStashFn);
127 }
128 }
129 },
130 multi: true,
131 },
132 {
133 provide: APP_BOOTSTRAP_LISTENER,

Callers 1

withIncrementalHydrationFunction · 0.90

Calls 15

injectFunction · 0.90
performanceMarkFeatureFunction · 0.90
setStashFnFunction · 0.90
sharedStashFunctionFunction · 0.90
sharedMapFunctionFunction · 0.90
shouldEnableEventReplayFunction · 0.85
initEventReplayFunction · 0.85
hasMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…