Skip to content

Commit cf3a028

Browse files
committed
Change window and document DOM access to self checks for SW context
Fixes #2867
1 parent c1245de commit cf3a028

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

packages/ts/frontend/src/Connect.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from './FluxConnection.js';
1717
import type { VaadinWindow } from './types.js';
1818

19-
const $wnd = window as VaadinWindow;
19+
const $wnd = self as VaadinWindow;
2020

2121
$wnd.Vaadin ??= {};
2222
$wnd.Vaadin.registrations ??= [];
@@ -300,7 +300,8 @@ export class ConnectClient {
300300
throw new TypeError(`2 arguments required, but got only ${arguments.length}`);
301301
}
302302

303-
const csrfHeaders = getCsrfTokenHeadersForEndpointRequest(document);
303+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
304+
const csrfHeaders = self.document ? getCsrfTokenHeadersForEndpointRequest(self.document) : {};
304305
const headers: Record<string, string> = {
305306
Accept: 'application/json',
306307
'Content-Type': 'application/json',

packages/ts/frontend/src/CookieManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ export function calculatePath({ pathname }: URL): string {
55
}
66

77
const CookieManager: Cookies.CookiesStatic = Cookies.withAttributes({
8-
path: calculatePath(new URL(document.baseURI)),
8+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
9+
path: calculatePath(new URL(self.document?.baseURI ?? '/')),
910
});
1011

1112
export default CookieManager;

packages/ts/frontend/src/FluxConnection.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ export class FluxConnection extends EventTarget {
182182
}
183183

184184
#connectWebsocket(prefix: string, atmosphereOptions: Partial<Atmosphere.Request>) {
185-
const extraHeaders = getCsrfTokenHeadersForEndpointRequest(document);
185+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
186+
const extraHeaders = self.document ? getCsrfTokenHeadersForEndpointRequest(self.document) : {};
186187
const pushUrl = 'HILLA/push';
187188
const url = prefix.length === 0 ? pushUrl : (prefix.endsWith('/') ? prefix : `${prefix}/`) + pushUrl;
188189
this.#socket = atmosphere.subscribe?.({

packages/ts/react-i18n/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class I18n {
3131

3232
constructor() {
3333
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
34-
if (!(window as any).Vaadin?.featureFlags?.hillaI18n) {
34+
if (!(self as any).Vaadin?.featureFlags?.hillaI18n) {
3535
// Remove when removing feature flag
3636
throw new Error(
3737
`The Hilla I18n API is currently considered experimental and may change in the future. To use it you need to explicitly enable it in Copilot or by adding com.vaadin.experimental.hillaI18n=true to vaadin-featureflags.properties`,

packages/ts/react-signals/src/FullStackSignal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export abstract class DependencyTrackingSignal<T> extends Signal<T> {
2828

2929
protected constructor(value: T | undefined, onFirstSubscribe: () => void, onLastUnsubscribe: () => void) {
3030
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
31-
if (!(window as any).Vaadin?.featureFlags?.fullstackSignals) {
31+
if (!(self as any).Vaadin?.featureFlags?.fullstackSignals) {
3232
// Remove when removing feature flag
3333
throw new Error(
3434
`The Hilla Fullstack Signals API is currently considered experimental and may change in the future. To use it you need to explicitly enable it in Copilot or by adding com.vaadin.experimental.fullstackSignals=true to vaadin-featureflags.properties`,

0 commit comments

Comments
 (0)