From 8325fb22fb70c5d2f931f26991cb6e72a448bff8 Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Sun, 26 Feb 2023 18:52:47 +0000 Subject: [PATCH 1/4] web: Remove hash from URL before appending it with the container id --- web/src/giscus.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/src/giscus.ts b/web/src/giscus.ts index c971fd58..b5716638 100644 --- a/web/src/giscus.ts +++ b/web/src/giscus.ts @@ -143,6 +143,7 @@ export class GiscusWidget extends LitElement { localStorage.setItem(this.GISCUS_SESSION_KEY, JSON.stringify(urlSession)); this.__session = urlSession; url.searchParams.delete('giscus'); + url.hash = ''; history.replaceState(undefined, document.title, url.toString()); return; } @@ -263,6 +264,7 @@ export class GiscusWidget extends LitElement { private _getCleanedUrl() { const url = new URL(location.href); url.searchParams.delete('giscus'); + url.hash = ''; return url; } From 14fc00dc76be86d238417525a75d102ffea2e5ed Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Sun, 26 Feb 2023 19:00:05 +0000 Subject: [PATCH 2/4] web: Handle signOut message --- web/src/giscus.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/web/src/giscus.ts b/web/src/giscus.ts index b5716638..bb747b6c 100644 --- a/web/src/giscus.ts +++ b/web/src/giscus.ts @@ -161,6 +161,12 @@ export class GiscusWidget extends LitElement { } } + private signOut() { + localStorage.removeItem(this.GISCUS_SESSION_KEY); + this.__session = ''; + this.update(new Map()); + } + private handleMessageEvent(event: MessageEvent) { if (event.origin !== this.host) return; @@ -171,6 +177,12 @@ export class GiscusWidget extends LitElement { this.iframeRef.style.height = `${data.giscus.resizeHeight}px`; } + if (data.giscus.signOut) { + console.log(`[giscus] User has logged out. Session has been cleared.`); + this.signOut(); + return; + } + if (!data.giscus.error) return; const message: string = data.giscus.error; @@ -182,11 +194,8 @@ export class GiscusWidget extends LitElement { ) { // Might be because token is expired or other causes if (localStorage.getItem(this.GISCUS_SESSION_KEY) !== null) { - localStorage.removeItem(this.GISCUS_SESSION_KEY); - this.__session = ''; console.warn(`${this._formatError(message)} Session has been cleared.`); - // Reload iframe - this.update(new Map()); + this.signOut(); return; } From 8ef2cf687ea3334d53a817131c6df88896d0b5e5 Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Sun, 26 Feb 2023 19:14:07 +0000 Subject: [PATCH 3/4] web: Check host before postMessage() and set config on initial load --- web/src/giscus.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/web/src/giscus.ts b/web/src/giscus.ts index bb747b6c..19b2d15e 100644 --- a/web/src/giscus.ts +++ b/web/src/giscus.ts @@ -217,6 +217,7 @@ export class GiscusWidget extends LitElement { } private sendMessage(message: T) { + if (!this.iframeRef || !this.iframeRef.src.startsWith(this.host)) return; this.iframeRef?.contentWindow?.postMessage({ giscus: message }, this.host); } @@ -242,9 +243,10 @@ export class GiscusWidget extends LitElement { } firstUpdated() { - this.iframeRef?.addEventListener('load', () => - this.iframeRef?.classList.remove('loading') - ); + this.iframeRef?.addEventListener('load', () => { + this.iframeRef?.classList.remove('loading'); + this.updateConfig(); + }); } requestUpdate( From 776dc3e2b28f20c21d3c179d3941247ed4bf069e Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Sun, 26 Feb 2023 19:22:26 +0000 Subject: [PATCH 4/4] web: Bump to 1.2.7 --- web/package-lock.json | 4 ++-- web/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/web/package-lock.json b/web/package-lock.json index 7162cdd3..ad241fda 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -1,12 +1,12 @@ { "name": "giscus", - "version": "1.2.6", + "version": "1.2.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "giscus", - "version": "1.2.6", + "version": "1.2.7", "license": "MIT", "dependencies": { "lit": "^2.6.1" diff --git a/web/package.json b/web/package.json index 44e8369b..afa17a72 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { "name": "giscus", - "version": "1.2.6", + "version": "1.2.7", "type": "module", "main": "dist/giscus.mjs", "module": "dist/giscus.mjs",