Skip to content

Commit 1fffb2c

Browse files
committed
fix(elements): ssr connected callbacks
1 parent a127114 commit 1fffb2c

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

elements/pf-back-to-top/pf-back-to-top.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ export class PfBackToTop extends LitElement {
158158
}
159159

160160
this.#scrollSpy = !!this.scrollableSelector;
161-
if (this.#scrollSpy && this.scrollableSelector) {
161+
if (isServer) {
162+
return;
163+
} else if (this.#scrollSpy && this.scrollableSelector) {
162164
const scrollableElement = this.#rootNode?.querySelector?.(this.scrollableSelector);
163165
if (!scrollableElement) {
164166
this.#logger.error(`unable to find element with selector ${this.scrollableSelector}`);

elements/pf-clipboard-copy/pf-clipboard-copy.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LitElement, html, type TemplateResult } from 'lit';
1+
import { LitElement, html, isServer, type TemplateResult } from 'lit';
22
import { customElement } from 'lit/decorators/custom-element.js';
33
import { property } from 'lit/decorators/property.js';
44
import { classMap } from 'lit/directives/class-map.js';
@@ -108,7 +108,9 @@ export class PfClipboardCopy extends LitElement {
108108
connectedCallback(): void {
109109
super.connectedCallback();
110110
this.#mo.observe(this, { characterData: true });
111-
this.#onMutation();
111+
if (!isServer) {
112+
this.#onMutation();
113+
}
112114
}
113115

114116
/**
@@ -167,7 +169,7 @@ export class PfClipboardCopy extends LitElement {
167169
}
168170

169171
#onMutation() {
170-
if (this.childNodes.length > 0) {
172+
if (this.childNodes?.length > 0) {
171173
this.value = this.getAttribute('value') ?? this.#dedent(Array.from(this.childNodes, child =>
172174
(child instanceof Element || child instanceof Text) ? (child.textContent ?? '') : '')
173175
.join(''));

elements/pf-table/pf-table.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ export class PfTable extends LitElement {
708708
}
709709

710710
#onSlotchange() {
711-
this.columns = this.querySelector('pf-tr')?.querySelectorAll('pf-th')?.length ?? 0;
711+
this.columns = this.querySelector?.('pf-tr')?.querySelectorAll('pf-th')?.length ?? 0;
712712
this.requestUpdate();
713713
}
714714

elements/pf-tabs/pf-tab.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LitElement, html, type TemplateResult } from 'lit';
1+
import { LitElement, html, isServer, type TemplateResult } from 'lit';
22
import { customElement } from 'lit/decorators/custom-element.js';
33
import { property } from 'lit/decorators/property.js';
44
import { queryAssignedElements } from 'lit/decorators/query-assigned-elements.js';
@@ -63,7 +63,7 @@ export class PfTab extends LitElement {
6363
static readonly styles: CSSStyleSheet[] = [styles];
6464

6565
@queryAssignedElements({ slot: 'icon', flatten: true })
66-
private icons!: HTMLElement[];
66+
private icons?: HTMLElement[];
6767

6868
@property({ reflect: true, type: Boolean }) active = false;
6969

@@ -105,13 +105,14 @@ export class PfTab extends LitElement {
105105
const { box, fill = false, vertical = false } = this.ctx ?? {};
106106
const light = box === 'light';
107107
const dark = box === 'dark';
108+
const icons = isServer ? [] : this.icons;
108109
return html`
109110
<div id="button"
110111
part="button"
111112
class="${classMap({ active, box: !!box, dark, light, fill, vertical })}">
112113
<slot name="icon"
113114
part="icon"
114-
?hidden="${!this.icons.length}"
115+
?hidden="${!icons?.length}"
115116
@slotchange="${() => this.requestUpdate()}"></slot>
116117
<slot part="text"></slot>
117118
</div>

elements/pf-tooltip/pf-tooltip.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ export class PfTooltip extends LitElement {
130130
}) flipBehavior?: Placement[];
131131

132132
get #invoker(): HTMLSlotElement | null {
133-
return this.shadowRoot?.querySelector('#invoker') ?? null;
133+
return this.shadowRoot?.querySelector?.('#invoker') ?? null;
134134
}
135135

136136
get #content(): HTMLElement | null {
137-
return this.shadowRoot?.querySelector('#tooltip') ?? null;
137+
return this.shadowRoot?.querySelector?.('#tooltip') ?? null;
138138
}
139139

140140
#referenceTrigger?: HTMLElement | null;

0 commit comments

Comments
 (0)