Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[labs/observers] Prevent failing in SSR #4591

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bright-yaks-wink.md
@@ -0,0 +1,5 @@
---
'@lit-labs/observers': patch
---

Do not initialize observers to prevent failing in SSR environment.
1 change: 1 addition & 0 deletions packages/labs/observers/package.json
Expand Up @@ -168,6 +168,7 @@
"@types/trusted-types": "^2.0.2"
},
"dependencies": {
"lit-html": "^2.4.0",
a11delavar marked this conversation as resolved.
Show resolved Hide resolved
"@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
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
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
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
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