MCPcopy Create free account
hub / github.com/UI5/webcomponents / connectedCallback

Function connectedCallback

packages/base/src/UI5Element.ts:325–384  ·  view source on GitHub ↗

* Do not call this method from derivatives of UI5Element, use "onEnterDOM" only * @private

()

Source from the content-addressed store, hash-verified

323 * @private
324 */
325 async connectedCallback() {
326 if (DEV_MODE) {
327 const props = (this.constructor as typeof UI5Element).getMetadata().getProperties();
328 for (const [prop, propData] of Object.entries(props)) { // eslint-disable-line
329 if (Object.hasOwn(this, prop) && !this.initializedProperties.has(prop)) {
330 // initialized properties should not trigger this error as they will be reassigned, only property initializers will trigger this in case unsupported TS mode
331 // eslint-disable-next-line no-console
332 console.error(`[UI5-FWK] ${(this.constructor as typeof UI5Element).getMetadata().getTag()} has a property [${prop}] that is shadowed by the instance. Updates to this property will not invalidate the component. Possible reason is TS target ES2022 or TS useDefineForClassFields`);
333 }
334 }
335 }
336
337 const ctor = this.constructor as typeof UI5Element;
338
339 registerElement(this);
340
341 this.setAttribute(ctor.getMetadata().getPureTag(), "");
342 if (ctor.getMetadata().supportsF6FastNavigation() && !this.hasAttribute("data-sap-ui-fastnavgroup")) {
343 this.setAttribute("data-sap-ui-fastnavgroup", "true");
344 }
345
346 const slotsAreManaged = ctor.getMetadata().slotsAreManaged();
347
348 this._inDOM = true;
349
350 if (slotsAreManaged) {
351 // always register the observer before yielding control to the main thread (await)
352 this._startObservingDOMChildren();
353 await this._processChildren();
354 }
355
356 if (!ctor.asyncFinished) {
357 await ctor._definePromise;
358 }
359
360 // Skip rendering while a language change is in progress to avoid rendering with not fully loaded locale data.
361 // Once the locale data is loaded, the language-aware component will be re-rendered.
362 if (ctor.getMetadata().isLanguageAware() && getLanguageChangePending()) {
363 return;
364 }
365
366 if (!this._inDOM) { // Component removed from DOM while _processChildren was running
367 return;
368 }
369
370 renderImmediately(this);
371 this._domRefReadyPromise._deferredResolve!();
372 this._fullyConnected = true;
373 this.onEnterDOM();
374
375 if (this.hasAttribute("autofocus")) {
376 // Honor the global `autofocus` HTML attribute. Done manually because
377 // Firefox/Safari close the autofocus window at end-of-parse, before
378 // async UI5 components have rendered their shadow DOM. Per HTML spec,
379 // only the first element with `autofocus` in document order wins.
380 requestAnimationFrame(() => {
381 this.focus();
382 });

Callers

nothing calls this directly

Calls 13

registerElementFunction · 0.85
getLanguageChangePendingFunction · 0.85
renderImmediatelyFunction · 0.85
getPropertiesMethod · 0.80
getMetadataMethod · 0.80
getTagMethod · 0.80
getPureTagMethod · 0.80
hasAttributeMethod · 0.80
slotsAreManagedMethod · 0.80
isLanguageAwareMethod · 0.80
onEnterDOMMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…