Skip to content

Commit 9769a5a

Browse files
authored
fix(material/tooltip): resolve server-side rendering error (#25728)
In a recent change MDC introduced a top-level reference to `window` which broke our server-side rendering check. These changes remove our dependency on MDC completely in order to fix the error.
1 parent 6526277 commit 9769a5a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/material/tooltip/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ ng_module(
2626
"//src/cdk/overlay",
2727
"//src/cdk/portal",
2828
"//src/material/core",
29-
"@npm//@material/tooltip",
3029
],
3130
)
3231

src/material/tooltip/tooltip.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import {
4949
ScrollStrategy,
5050
VerticalConnectionPos,
5151
} from '@angular/cdk/overlay';
52-
import {numbers} from '@material/tooltip';
5352
import {ComponentPortal} from '@angular/cdk/portal';
5453
import {Observable, Subject} from 'rxjs';
5554

@@ -156,6 +155,13 @@ const passiveListenerOptions = normalizePassiveListenerOptions({passive: true});
156155
*/
157156
const LONGPRESS_DELAY = 500;
158157

158+
// These constants were taken from MDC's `numbers` object. We can't import them from MDC,
159+
// because they have some top-level references to `window` which break during SSR.
160+
const MIN_VIEWPORT_TOOLTIP_THRESHOLD = 8;
161+
const UNBOUNDED_ANCHOR_GAP = 8;
162+
const MIN_HEIGHT = 24;
163+
const MAX_WIDTH = 200;
164+
159165
@Directive()
160166
export abstract class _MatTooltipBase<T extends _TooltipComponentBase>
161167
implements OnDestroy, AfterViewInit
@@ -880,11 +886,11 @@ export class MatTooltip extends _MatTooltipBase<TooltipComponent> {
880886
defaultOptions,
881887
_document,
882888
);
883-
this._viewportMargin = numbers.MIN_VIEWPORT_TOOLTIP_THRESHOLD;
889+
this._viewportMargin = MIN_VIEWPORT_TOOLTIP_THRESHOLD;
884890
}
885891

886892
protected override _addOffset(position: ConnectedPosition): ConnectedPosition {
887-
const offset = numbers.UNBOUNDED_ANCHOR_GAP;
893+
const offset = UNBOUNDED_ANCHOR_GAP;
888894
const isLtr = !this._dir || this._dir.value == 'ltr';
889895

890896
if (position.originY === 'top') {
@@ -1138,6 +1144,6 @@ export class TooltipComponent extends _TooltipComponentBase {
11381144
/** Whether the tooltip text has overflown to the next line */
11391145
private _isTooltipMultiline() {
11401146
const rect = this._elementRef.nativeElement.getBoundingClientRect();
1141-
return rect.height > numbers.MIN_HEIGHT && rect.width >= numbers.MAX_WIDTH;
1147+
return rect.height > MIN_HEIGHT && rect.width >= MAX_WIDTH;
11421148
}
11431149
}

0 commit comments

Comments
 (0)