Initial Commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
// React-tier polyfills. Base webcrypto comes from `@suaveplan/testing/polyfills`;
|
||||
// this file adds the `IS_REACT_ACT_ENVIRONMENT` flag React DOM looks for when
|
||||
// state updates happen outside an explicit `act(...)` wrapper, plus a minimal
|
||||
// `URL.createObjectURL`/`revokeObjectURL` shim because happy-dom does not
|
||||
// implement them and the underlying `PackedResourceManager` calls them on
|
||||
// every load.
|
||||
|
||||
interface ReactActEnvWindow {
|
||||
IS_REACT_ACT_ENVIRONMENT?: boolean;
|
||||
}
|
||||
|
||||
const win = globalThis as unknown as ReactActEnvWindow;
|
||||
if (win.IS_REACT_ACT_ENVIRONMENT === undefined) {
|
||||
win.IS_REACT_ACT_ENVIRONMENT = true;
|
||||
}
|
||||
|
||||
interface ObjectUrlGlobals {
|
||||
URL: {
|
||||
createObjectURL?: (obj: Blob) => string;
|
||||
revokeObjectURL?: (url: string) => void;
|
||||
};
|
||||
}
|
||||
|
||||
const urlGlobals = globalThis as unknown as ObjectUrlGlobals;
|
||||
let counter = 0;
|
||||
if (typeof urlGlobals.URL.createObjectURL !== "function") {
|
||||
urlGlobals.URL.createObjectURL = (_blob: Blob): string => {
|
||||
counter += 1;
|
||||
return `blob:react-packer/${counter}`;
|
||||
};
|
||||
}
|
||||
if (typeof urlGlobals.URL.revokeObjectURL !== "function") {
|
||||
urlGlobals.URL.revokeObjectURL = (_url: string): void => {
|
||||
// no-op shim — happy-dom doesn't track blob URLs
|
||||
};
|
||||
}
|
||||
|
||||
interface FontShim {
|
||||
fonts?: {
|
||||
load?: (spec: string) => Promise<FontFace[]>;
|
||||
add?: (font: FontFace) => unknown;
|
||||
};
|
||||
}
|
||||
const docShim = (globalThis as { document?: FontShim }).document;
|
||||
if (docShim !== undefined && docShim.fonts === undefined) {
|
||||
docShim.fonts = {
|
||||
load: async (_spec: string): Promise<FontFace[]> => [],
|
||||
add: (_font: FontFace): unknown => undefined,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user