Skip to content

Commit

Permalink
Merge pull request #4401 from preactjs/devtools-global-check
Browse files Browse the repository at this point in the history
devtools: prefer `globalThis` over `window` if available
  • Loading branch information
marvinhagemeister authored May 29, 2024
2 parents a263130 + eb3fb62 commit d19017e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions devtools/src/devtools.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { options, Fragment, Component } from 'preact';
import { Component, Fragment, options } from 'preact';

export function initDevTools() {
if (typeof window != 'undefined' && window.__PREACT_DEVTOOLS__) {
window.__PREACT_DEVTOOLS__.attachPreact('10.22.0', options, {
const globalVar =
typeof globalThis !== 'undefined'
? globalThis
: typeof window !== 'undefined'
? window
: undefined;

if (
globalVar !== null &&
globalVar !== undefined &&
globalVar.__PREACT_DEVTOOLS__
) {
globalVar.__PREACT_DEVTOOLS__.attachPreact('10.22.0', options, {
Fragment,
Component
});
Expand Down

0 comments on commit d19017e

Please sign in to comment.