Skip to content

fix: guard against undefined contentWindow in GiscusComments#1948

Merged
sanjay-kv merged 1 commit into
recodehive:mainfrom
bh462007:fix/giscus-contentwindow-null-check
Jul 9, 2026
Merged

fix: guard against undefined contentWindow in GiscusComments#1948
sanjay-kv merged 1 commit into
recodehive:mainfrom
bh462007:fix/giscus-contentwindow-null-check

Conversation

@bh462007

@bh462007 bh462007 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1933

The GiscusComments component sends a postMessage to the giscus iframe whenever colorMode changes. While it already checked if the iframe existed, it didn't verify that the iframe had finished loading.

If colorMode changed before iframe.contentWindow became available, calling postMessage would throw a TypeError.

Fix

Extended the existing guard to ensure both the iframe and its contentWindow are available before sending the message.

if (!iframe || !iframe.contentWindow) {
  return;
}

Testing

  • Ran the project locally using npm run start.
  • Reproduced the issue with an isolated test where contentWindow was undefined, confirming the Cannot read properties of undefined (reading 'postMessage') error.
  • Verified that toggling the theme on blog posts with Giscus comments no longer produces console errors after the fix.

Copilot AI review requested due to automatic review settings July 8, 2026 12:32
@bh462007 bh462007 requested a review from Adez017 as a code owner July 8, 2026 12:32
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@bh462007 is attempting to deploy a commit to the recode Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. The estimated time for response is 5–8 hrs.

In the meantime, please provide all necessary screenshots and make sure you run - npm build run , command and provide a screenshot, a video recording, or an image of the update you made below, which helps speed up the review and assignment. If you have questions, reach out to LinkedIn. Your contributions are highly appreciated!😊

Note: I maintain the repo issue every day twice at 8:00 AM IST and 9:00 PM IST. If your PR goes stale for more than one day, you can tag and comment on this same issue by tagging @sanjay-kv.

We are here to help you on this journey of open source. Consistent 20 contributions are eligible for sponsorship 💰

🎁 check our list of amazing people we sponsored so far: GitHub Sponsorship. ✨

📚Your perks for contribution to this community 👇🏻

  1. Get free Consultation use code recode50 to get free: Mentorship for free.

  2. Get the Ebook for free use code recode at checkout: Data Science cheatsheet for Beginners.

  3. Check out this weekly Newsletter: Sanjay's Newsletter.

If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊

@github-actions github-actions Bot added in-review The current changes are in review and would need approval and testing before merging level 1 10 points recode this is label for leaderboard labels Jul 8, 2026
@github-actions github-actions Bot added this to the recode:launch 3.0 milestone Jul 8, 2026
@github-actions github-actions Bot added area:UI Related to UI/UX. For Frontend Developers. Enhacement gssoc26 label roadmap The issues /PR that are big changes on the roadmap labels Jul 8, 2026
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

✅ Synchronized metadata from Issue #1933:

  • Labels: area:UI, roadmap, level 1, recode, Enhacement
  • Milestone: recode:live 2.0

@iitzIrFan iitzIrFan moved this to In Progress in @recode-web Jul 8, 2026
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
recode-website Ready Ready Preview, Comment Jul 9, 2026 11:45pm

@sanjay-kv sanjay-kv merged commit 5acfba4 into recodehive:main Jul 9, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in @recode-web Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:UI Related to UI/UX. For Frontend Developers. Enhacement gssoc26 label in-review The current changes are in review and would need approval and testing before merging level 1 10 points recode this is label for leaderboard roadmap The issues /PR that are big changes on the roadmap

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[bug]: GiscusComments crashes when theme toggles before iframe finishes loading

4 participants