Skip to content

Commit

Permalink
Fix bug in frame hiding, add more safeguards
Browse files Browse the repository at this point in the history
  • Loading branch information
chocolatkey authored Jan 16, 2025
1 parent d89aa8d commit eb61441
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion navigator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@readium/navigator",
"version": "1.3.3",
"version": "1.3.4",
"type": "module",
"description": "Next generation SDK for publications in Web Apps",
"author": "readium",
Expand Down
15 changes: 9 additions & 6 deletions navigator/src/epub/frame/FrameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class FrameManager {
private loader: Loader | undefined;
public readonly source: string;
private comms: FrameComms | undefined;
private destroyed: boolean = false;

private currModules: ModuleName[] = [];

Expand Down Expand Up @@ -57,15 +58,17 @@ export class FrameManager {
await this.hide();
this.loader?.destroy();
this.frame.remove();
this.destroyed = true;
}

async hide(): Promise<void> {
if(this.destroyed) return;
this.frame.style.visibility = "hidden";
this.frame.style.setProperty("aria-hidden", "true");
this.frame.style.opacity = "0";
this.frame.style.pointerEvents = "none";
if(this.frame.parentElement) {
if(this.comms === undefined) return;
if(this.comms === undefined || !this.comms.ready) return;
return new Promise((res, _) => {
this.comms?.send("unfocus", undefined, (_: boolean) => {
this.comms?.halt();
Expand All @@ -77,10 +80,8 @@ export class FrameManager {
}

async show(atProgress?: number): Promise<void> {
if(!this.frame.parentElement) {
console.warn("Trying to show frame that is not attached to the DOM");
return;
}
if(this.destroyed) throw Error("Trying to show frame when it doesn't exist");
if(!this.frame.parentElement) throw Error("Trying to show frame that is not attached to the DOM");
if(this.comms) this.comms.resume();
else this.comms = new FrameComms(this.frame.contentWindow!, this.source);
return new Promise((res, _) => {
Expand All @@ -104,15 +105,17 @@ export class FrameManager {
}

get iframe() {
if(this.destroyed) throw Error("Trying to use frame when it doesn't exist");
return this.frame;
}

get realSize() {
if(this.destroyed) throw Error("Trying to use frame client rect when it doesn't exist");
return this.frame.getBoundingClientRect();
}

get window() {
if(!this.frame.contentWindow) throw Error("Trying to use frame window when it doesn't exist");
if(this.destroyed || !this.frame.contentWindow) throw Error("Trying to use frame window when it doesn't exist");
return this.frame.contentWindow;
}

Expand Down

0 comments on commit eb61441

Please sign in to comment.