Merge pull request #393 from PR0M3TH3AN/codex/fix-video-modal-initialization-issue

Fix video modal rehydration after back navigation
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2025-10-09 20:10:56 -04:00
commit b78337af6d
2 files changed
+40 -4

No files matched your search

+18 -2
View File
@@ -1313,9 +1313,25 @@ class Application {
const existingVideoElement = getVideoElement();
if (existingRoot && existingRoot.isConnected) {
if (ensureVideoElement && !existingVideoElement) {
throw new Error("Video modal video element is not ready.");
if (!existingVideoElement && ensureVideoElement) {
if (typeof this.videoModal.load === "function") {
await this.videoModal.load();
}
const rehydratedRoot = getRoot();
const rehydratedVideoElement = getVideoElement();
if (!rehydratedVideoElement) {
throw new Error("Video modal video element is not ready.");
}
this.modalVideo = rehydratedVideoElement;
return {
root: rehydratedRoot || existingRoot,
videoElement: rehydratedVideoElement,
};
}
if (existingVideoElement) {
this.modalVideo = existingVideoElement;
}
+22 -2
View File
@@ -127,8 +127,28 @@ export class VideoModal {
}
async load() {
if (this.loaded && this.playerModal && this.playerModal.isConnected) {
return this.playerModal;
if (this.loaded) {
const root = this.playerModal;
const rootConnected = root && root.isConnected;
if (rootConnected) {
const video = this.modalVideo;
const videoConnected = video && video.isConnected;
if (!videoConnected) {
const existingVideo = root.querySelector("#modalVideo");
if (existingVideo) {
this.hydrate(root);
if (this.modalVideo && this.modalVideo.isConnected) {
return this.playerModal;
}
}
this.loaded = false;
} else {
return this.playerModal;
}
} else {
this.loaded = false;
this.playerModal = null;
}
}
const existing = this.document.getElementById("playerModal");