Replies: 8 comments 23 replies
-
I think this should be a line in the sand for this requirement. Maybe splitting the cache is an acceptable way to achieve this? I think we could have a larger discussion about cache splitting (around logged in state specifically, but maybe other things) but, in short, maybe it's worth it? Here's a good reference for an approach to enabling server side rendering of a page in the reader's desired colour scheme: https://web.dev/user-preference-media-features-headers/ |
Beta Was this translation helpful? Give feedback.
-
I just did a very quick poc to see if we could:
It works. I simply have a :root {
--color: rgb(250, 250, 250);
--background-color: rgb(5, 5, 5);
} These css files are loaded in the <link
rel="stylesheet"
href="${CDN}static/frontend/css/dark.css"
media="(prefers-color-scheme: dark)"
/>
<link
rel="stylesheet"
href="${CDN}static/frontend/css/light.css"
media="(prefers-color-scheme: light)"
/> and then in const WHITE = neutral[100];
const BLACK = neutral[7]; with const WHITE = 'var(--background-color)';
const BLACK = 'var(--color)'; and it carries through Screen.Recording.2021-10-16.at.15.08.47.movScreen.Recording.2021-10-16.at.15.23.13.movI used a web component for the toggle Problems with this implementationPage refreshes cause a flash of unwanted styles. Either we think about cache splitting or implement a style dependency in the page load? |
Beta Was this translation helpful? Give feedback.
-
How to choose dark colours?I think it's worth thinking about what steps would be needed to make the task of deciding the dark palette easier. Centralise all colour decisionsRight now, in DCR, we make the vast majority of colour choices using This task would be simple. It's a chore but you could spread the work with a mob session. Use Storybook as a design tool?Maybe when the designers are building out Controversial and possibly stupid question: Do we even need Figma designs? Extend the layout storybook storiesWe should exactly double the number of stories that we capture for each article layout. So instead of having |
Beta Was this translation helpful? Give feedback.
-
Spike implementationThis branch has a spike with dark mode implemented on DCR. https://github.com/guardian/dotcom-rendering/tree/oliver/dark-mode-poc This spike is aiming to respect each of the points listed in the description above
CSS VariablesI'm using css variables to provide the browser with a way to change styles without the need for a re-render. Styles are split between two files, This also means we don't depend on either React or Emotion so there's no Context and no re-render. Looking at twitter.com, it looks like they are not doing this and there's a re-render which isn't horrible, but isn't smooth like, say, https://overreacted.io/ Finally, by using css vars we have the option to add a small animation to color transitions, which is nice. Link tagsThe two different css files ( ToggleI'm using a web component provided by the Chrome team, It respects The only feature I added to this off the shelf solution is a listener that changes the class on the body tag when the toggle is clicked. Support SSRDark mode + SSR is slightly tricky as the server needs to be aware of the mode the client is in. If not, you either have to delay the first render until you know their preference or you get flash of unstyled content. There's a user preference header that gets sent based on a user's system preference, we can read that and decide what to render on the client. This header would also need to be added to the Vary header, splitting the cache. Not solvedThe user preference header contains the system setting but we also need to send any local, site specific, preference using that to override the system value. This is, I presume, possible with a cookie. Change entire page background colour to further improve transitions |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Do we need to split the cache?To prevent a flash of unstyled content I think we need to serve the user with html that already has the correct css inlined for their preferred mode, dark or light. If we don't do this, the browser will first render the default, light css, and then replace it with what it reads from the browser. Causing the flash. The only other way to prevent this that I can think of - other than splitting the cache - is to delay rendering until we have the user's preference. Not ideal! Are there other approaches? |
Beta Was this translation helpful? Give feedback.
-
Rollout strategyI think we should consider what are essential requirements, and what can be added after an initial rollout. Allowing “users to opt in and out of dark mode using a toggle, regardless of platform-level preferences” might not need to be in the initial dark mode support. 3-step which can overlap
|
Beta Was this translation helpful? Give feedback.
-
hello everyone, there doesn't seem to be much progress on this. Would it be pôssible to implement one option and put it live, and then see where (if needed) any improvements could be made ? As a user of the web version of the Guardian, it's becoming extremely annoying that there is no dark mode. |
Beta Was this translation helpful? Give feedback.
-
Currently we support dark mode in apps and it's inevitable that web will follow. Source components will need to support dark mode. It would be useful to define patterns allowing all our web products to provide dark mode support in a consistent way.
Possible requirements
List what possible requirements we need to consider for a dark mode solution.
Defining colour schemes
prefers-color-scheme
media feature)Source components
Possible solutions
darkModeCss
currently used inapps-rendering
supportsDarkMode
prop for all Source components. When set totrue
by the platform, component may ship dark mode CSSDiscussion
Prior discussion
darkModeCss
Helper #800Beta Was this translation helpful? Give feedback.
All reactions