Skip to content

Conversation

gordonwoodhull
Copy link
Contributor

Simpler alternative to #12608

Wait for giscus to load and then set its light/dark toggle immediately.

This is failing on Safari. May still need a Mutation Observer for the iframe.

@gordonwoodhull gordonwoodhull requested a review from cderv April 23, 2025 22:45
@posit-snyk-bot
Copy link
Collaborator

posit-snyk-bot commented Apr 23, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@gordonwoodhull gordonwoodhull marked this pull request as ready for review April 24, 2025 00:02
@gordonwoodhull
Copy link
Contributor Author

gordonwoodhull commented Apr 24, 2025

Okay, it works with a MutationObserver waiting for giscus to load.

Although this is a long chain of callbacks, and we did not manage to avoid MutationObserver, IMO this is simpler and more straightforward than dynamically loading the giscus script.

I wish I could keep going and remove the author preference from the giscus parameters, since it makes things more complicated to have the base and alternate themes swapped, and I don't see what it helps.

But think it’s easier and safer to expose const authorPrefersDark and fix the "reversed giscus" bug directly (first commit).

not user preference

which is kind of silly because it's usually the user's preference
that matters, see next commit
i did see the iframe query fail once, but was unable to repro
otherwise this seems to be reliable
because safari will run before giscus.js has created everything
@gordonwoodhull gordonwoodhull force-pushed the bugfix/giscus-light-dark-toggle-on-load branch from 865d5c8 to e73d522 Compare April 24, 2025 13:36
@gordonwoodhull gordonwoodhull merged commit 791f825 into main Apr 24, 2025
49 checks passed
@gordonwoodhull gordonwoodhull deleted the bugfix/giscus-light-dark-toggle-on-load branch April 24, 2025 15:53
@feinmann
Copy link

feinmann commented May 6, 2025

I just found this, because in my quarto blog, deployed as gh-pages, giscus is not loading and I see in my javascript console the following:

Uncaught ReferenceError: authorPrefersDark is not defined

Any idea?

@gordonwoodhull
Copy link
Contributor Author

Thanks @feinmann, I am able to reproduce with a site with Giscus but no dark mode.

I'll look into a fix for this.

@gordonwoodhull
Copy link
Contributor Author

@feinmann, this is fixed in 1.7.31

@feinmann
Copy link

Thank you for the great work! It is already deployed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants