Skip to content

Commit

Permalink
Adjust library to be used in Service Worker context without DOM globa…
Browse files Browse the repository at this point in the history
…l variables

Fixes vaadin/hilla#2867
  • Loading branch information
krissvaa committed Nov 11, 2024
1 parent 9a14915 commit aaed4b3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions frontend/packages/common-frontend/src/ConnectionIndicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,10 @@ export class ConnectionIndicator extends LitElement {

private timeoutFor(timeoutId: number, enabled: boolean, handler: () => void, delay: number): number {
if (timeoutId !== 0) {
self.window.clearTimeout(timeoutId);
self.clearTimeout(timeoutId);
}

return enabled ? self.window.setTimeout(handler, delay) : 0;
return enabled ? self.setTimeout(handler, delay) : 0;
}

static get instance(): ConnectionIndicator {
Expand Down
3 changes: 2 additions & 1 deletion frontend/packages/common-frontend/src/ConnectionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ export const isLocalhost = (hostname: string) => {
const $wnd = self as any;
if (!$wnd.Vaadin?.connectionState) {
let online;
if (isLocalhost(self.window.location.hostname)) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (self.location && isLocalhost(self.location.hostname)) {
// We do not know if we are online or not as we cannot trust navigator.onLine which checks availability of a network connection. Better to assume online so localhost apps can work
online = true;
} else {
Expand Down

0 comments on commit aaed4b3

Please sign in to comment.