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

fix: use self instead of window or document for worker context #16

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions frontend/packages/common-frontend/src/ConnectionIndicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class ConnectionIndicator extends LitElement {
* window.Vaadin.connectionIndicator and add instance to the document body.
*/
static create(): ConnectionIndicator {
const $wnd = window as any;
const $wnd = self as any;
if (!$wnd.Vaadin?.connectionIndicator) {
$wnd.Vaadin ??= {};
$wnd.Vaadin.connectionIndicator = document.createElement('vaadin-connection-indicator');
Expand Down 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) {
window.clearTimeout(timeoutId);
self.clearTimeout(timeoutId);
}

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

static get instance(): ConnectionIndicator {
Expand Down
5 changes: 3 additions & 2 deletions frontend/packages/common-frontend/src/ConnectionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,11 @@ export const isLocalhost = (hostname: string) => {
return false;
};

const $wnd = window as any;
const $wnd = self as any;
if (!$wnd.Vaadin?.connectionState) {
let online;
if (isLocalhost(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
2 changes: 1 addition & 1 deletion frontend/packages/common-frontend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './ConnectionState.js';
export * from './ConnectionIndicator.js';

const $wnd = window as any;
const $wnd = self as any;
$wnd.Vaadin ??= {};
$wnd.Vaadin.registrations ??= [];
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
Expand Down
Loading