Skip to content

Commit

Permalink
Move repluggableAppDebug to use globalThis (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
ma-cohen authored Jan 28, 2025
1 parent 21fdf5f commit c0418a2
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions src/hot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export function hot(sourceModule: any, entryPoints: EntryPoint[], host?: AppHost
}

const getHostInstance = () => {
const hostInstance = host ?? window.repluggableAppDebug?.host
const hostInstance = host ?? globalThis.repluggableAppDebug?.host
if (!hostInstance) {
console.error(
`HMR error: cannot find host object.\n` +
`hot(...) was called without the optional host parameter, and the fallback window.repluggableAppDebug.host doesn't exist`
`hot(...) was called without the optional host parameter, and the fallback globalThis.repluggableAppDebug.host doesn't exist`
)
}

Expand Down
5 changes: 2 additions & 3 deletions src/repluggableAppDebug/debug.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { AnyExtensionSlot } from '../extensionSlot'
import { Hot } from '../hot'

declare global {
interface Window {
repluggableAppDebug: RepluggableAppDebugInfo
}
// Have to use var is this variable reassigned in the global scope
var repluggableAppDebug: RepluggableAppDebugInfo
}

export interface RepluggableAppDebugInfo {
Expand Down
8 changes: 4 additions & 4 deletions src/repluggableAppDebug/repluggableAppDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ function mapApiToEntryPoint(allPackages: EntryPoint[]) {
*/
const getAllEntryPoints = () => {
return [
...window.repluggableAppDebug.utils.unReadyEntryPoints(),
...[...window.repluggableAppDebug.addedShells].map(([_, shell]) => shell.entryPoint)
...globalThis.repluggableAppDebug.utils.unReadyEntryPoints(),
...[...globalThis.repluggableAppDebug.addedShells].map(([_, shell]) => shell.entryPoint)
]
}

Expand Down Expand Up @@ -172,11 +172,11 @@ export function setupDebugInfo({
performance: getPerformanceDebug(options, trace, memoizedArr)
}

if (typeof window === 'undefined') {
if (typeof globalThis === 'undefined') {
return
}

window.repluggableAppDebug = {
globalThis.repluggableAppDebug = {
host,
uniqueShellNames,
extensionSlots,
Expand Down
2 changes: 1 addition & 1 deletion test/repluggableAppDebug.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const unreadAPI = { name: 'unreadyAPI' }

const getUnreadyAPIs = async () => {
await new Promise(resolve => setTimeout(resolve, 0))
return window.repluggableAppDebug.utils.getRootUnreadyAPI()
return globalThis.repluggableAppDebug.utils.getRootUnreadyAPI()
}

describe('RepluggableAppDebug', () => {
Expand Down
2 changes: 1 addition & 1 deletion testKit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function createAppHostAndWaitForLoading(packages: EntryPointOrPacka

const timeoutPromise = new Promise((resolve, reject) => {
setTimeout(() => {
const readyAPIs = Array.from(window.repluggableAppDebug.readyAPIs)
const readyAPIs = Array.from(globalThis.repluggableAppDebug.readyAPIs)
const unreadyAPIs = declaredAPIs.filter(api => !readyAPIs.some(readyAPI => readyAPI.name === api.name))
reject(
new Error(
Expand Down

0 comments on commit c0418a2

Please sign in to comment.