Skip to content

Commit

Permalink
[labs/observers] Prevent failing in SSR (#4591)
Browse files Browse the repository at this point in the history
  • Loading branch information
a11delavar authored Jul 3, 2024
1 parent feccc1b commit 045b6f1
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/bright-yaks-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lit-labs/observers': patch
---

Do not initialize observers to prevent failing in SSR environment.
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/labs/observers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
"@types/trusted-types": "^2.0.2"
},
"dependencies": {
"lit-html": "^2.4.0 || ^3.0.0",
"@lit/reactive-element": "^1.0.0 || ^2.0.0"
},
"publishConfig": {
Expand Down
4 changes: 4 additions & 0 deletions packages/labs/observers/src/intersection-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
import {isServer} from 'lit-html/is-server.js';
import {
ReactiveController,
ReactiveControllerHost,
Expand Down Expand Up @@ -94,6 +95,9 @@ export class IntersectionController<T = unknown> implements ReactiveController {
}
this._skipInitial = skipInitial ?? this._skipInitial;
this.callback = callback;
if (isServer) {
return;
}
// Check browser support.
if (!window.IntersectionObserver) {
console.warn(
Expand Down
4 changes: 4 additions & 0 deletions packages/labs/observers/src/mutation-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
import {isServer} from 'lit-html/is-server.js';
import {
ReactiveController,
ReactiveControllerHost,
Expand Down Expand Up @@ -94,6 +95,9 @@ export class MutationController<T = unknown> implements ReactiveController {
this._config = config;
this._skipInitial = skipInitial ?? this._skipInitial;
this.callback = callback;
if (isServer) {
return;
}
// Check browser support.
if (!window.MutationObserver) {
console.warn(
Expand Down
4 changes: 4 additions & 0 deletions packages/labs/observers/src/performance-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
import {isServer} from 'lit-html/is-server.js';
import {
ReactiveController,
ReactiveControllerHost,
Expand Down Expand Up @@ -80,6 +81,9 @@ export class PerformanceController<T = unknown> implements ReactiveController {
this._config = config;
this._skipInitial = skipInitial ?? this._skipInitial;
this.callback = callback;
if (isServer) {
return;
}
// Check browser support.
if (!window.PerformanceObserver) {
console.warn(
Expand Down
4 changes: 4 additions & 0 deletions packages/labs/observers/src/resize-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
import {isServer} from 'lit-html/is-server.js';
import {
ReactiveController,
ReactiveControllerHost,
Expand Down Expand Up @@ -93,6 +94,9 @@ export class ResizeController<T = unknown> implements ReactiveController {
this._config = config;
this._skipInitial = skipInitial ?? this._skipInitial;
this.callback = callback;
if (isServer) {
return;
}
// Check browser support.
if (!window.ResizeObserver) {
console.warn(
Expand Down

0 comments on commit 045b6f1

Please sign in to comment.