Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/pkgsite: dark theme preference not persisting #47423

Closed
nishanths opened this issue Jul 27, 2021 · 4 comments
Closed

x/pkgsite: dark theme preference not persisting #47423

nishanths opened this issue Jul 27, 2021 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. pkgsite

Comments

@nishanths
Copy link

nishanths commented Jul 27, 2021

What is the URL of the page with the issue?

e.g. https://pkg.go.dev/net/http

But not https://pkg.go.dev/license-policy.

What is your user agent?

Google Chrome:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36

Screenshot

Not useful.

What did you do?

The issue is possibly related to cookies, hence the use of incognito browser window for reliable reproducibility.

To preface, my system uses a light theme.

In a new incognito window:

  • Go to https://pkg.go.dev/net/http.
  • Light theme is rendered, as expected.
  • Pressed t (keyboard shortcut, albeit undocumented, to toggle light/dark mode).
  • Page switched to dark theme, as expected.
  • Inspected cookies by logging document.cookie; it contains prefers-color-scheme=dark, as expected.
  • Reloaded the page.

What did you expect to see?

The page to render in dark mode.

What did you see instead?

The page rendered in light mode.

It appears that the cookie prefers-color-scheme isn't being respected.

If I repeat the above steps for the URL https://pkg.go.dev/license-policy in a separate incognito window, the dark theme preference is respected. So it appears to also be something to do with package pages (e.g. net/http) vs. "static" pages (license-policy).

@gopherbot gopherbot added this to the Unreleased milestone Jul 27, 2021
@jba jba modified the milestones: Unreleased, pkgsite/unplanned Jul 27, 2021
@nishanths
Copy link
Author

nishanths commented Jul 27, 2021

Debugging notes

https://pkg.go.dev/net/http:

I tried three kinds of requests with curl/7.64.1 to debug.

% curl -sN 'https://pkg.go.dev/net/http' | head # no cookie
% curl -sN --cookie 'prefers-color-scheme=light' 'https://pkg.go.dev/net/http' | head # explicit light-theme cookie
% curl -sN --cookie 'prefers-color-scheme=dark' 'https://pkg.go.dev/net/http' | head # explicit dark-theme cookie

For all three requests, the response HTML looked like the following. But I would have expected it to have data-theme="dark" for the last request.

<html lang="en" data-layout="responsive" >

https://pkg.go.dev/license-policy:

Next, I tried the same with the license-policy page.

% curl -sN 'https://pkg.go.dev/license-policy' | head
% curl -sN --cookie 'prefers-color-scheme=light'  'https://pkg.go.dev/license-policy' | head
% curl -sN --cookie 'prefers-color-scheme=dark'  'https://pkg.go.dev/license-policy' | head

The first two responses, as expected:

<html lang="en" data-layout="" >

The last one, as expected:

<html lang="en" data-layout="" data-theme="dark">

@jba jba added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 27, 2021
@gopherbot
Copy link

Change https://golang.org/cl/337769 mentions this issue: Revert "internal,static: toggled user theme preference persists across pageviews"

@jamalc
Copy link

jamalc commented Jul 27, 2021

Thank you for the detailed issue! The keyboard shortcut wasn't documented yet because it was mainly intended for debugging purposes. The caching strategy we use for the documentation page complicates setting a persistent theme choice that is rendered on the server. We'll need to rely on the visitors system-wide prefers-color-scheme setting while we implement a workaround.

gopherbot pushed a commit to golang/pkgsite that referenced this issue Jul 27, 2021
…s pageviews"

This reverts commit f9028c5.

Reason for revert: Toggled color scheme persists in the cache for all users of pkg.go.dev.

For golang/go#47423
Fixes golang/go#47421

Change-Id: Ib3294d5ee0c7055f884661f1d4225e130e38d548
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/337769
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Trust: Jamal Carvalho <jamal@golang.org>
@gopherbot
Copy link

Change https://golang.org/cl/337870 mentions this issue: internal,static: add keyboard shortcut to override color scheme

@rsc rsc unassigned jamalc Jun 23, 2022
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. pkgsite
Projects
None yet
Development

No branches or pull requests

4 participants