Comments (7)
I think you misunderstood what I meant.
Using dark theme by default is just a temporary fix that reduces the impact, because a dark flash within a white screen is less harmful than a light flash within a dark screen.
I understand how it is difficult to load the expected theme at the server side, which is exactly what I explained before. Therefore, my proposal is to change the concept of a theme.
Previously, themes can be:
- default-light.theme
- default-dark.theme
- custom-light.theme
- custom-dark.theme
I suggest to distinguish the concept of "color scheme" and "theme". A "theme" must include two color schemes: light and dark:
- default.theme
- light.scheme
- dark.scheme
- custom.theme
- light.scheme
- dark.scheme
In other words, the light and dark schemes comes naturally with a theme's CSS files. The two schemes are always loaded together.
Within a theme's stylesheet, it could be something like this.
default.theme.scss:
@media (prefer-color-scheme: light) {
:root {
@include light-scheme();
}
}
@media (prefer-color-scheme: dark) {
:root {
@include dark-scheme();
}
}
:root[data-scheme=light] {
@include light-scheme();
}
:root[data-scheme=dark] {
@include dark-scheme();
}
- Before hydration (before the script are loaded), the color scheme follows the
prefer-color-scheme
media query, so we can always ensure that it matches the user's operating system's default setting. - After hydration (after the scripts are executed), the color scheme can be programmatically determined by the
data-scheme
attribute of the<html>
element.
In most cases, the user would expect to see the color scheme to match their OS settings, so this solution works perfectly fine.
In rare cases, the user might specify a different color scheme from their OS setting, e.g. use a light scheme when the OS setting is dark. This would cause a flash, but it wouldn't harm the user's eyes, because the initial color scheme always matches the OS setting.
from ng-doc.
Thank you for the explanation. I like this solution. I think I'll do something similar. I'll need to think a little more because previously I also wanted to add a layout setting to the theme, so that it would be possible to make fullscreen themes, which requires preconfiguring the sidebar. But now it seems to me that this should not be part of the theme but rather just separate layout settings.
from ng-doc.
This is a known bug that appeared with the transition to SSR. It will be addressed within another ticket (#126 which includes a discussion of this issue), so I'll close this one as a duplicate.
As for the default theme, I think I'll leave everything as is to avoid sudden breaking changes. In any case, with the bug fix, there shouldn't be any more issues with the dark theme.
from ng-doc.
Glad to know the default theme fix is already in progress.
However, what do you think of the first screen before hydration?
It is theoretically not possible to know the user's prefer-color-scheme
at the server side. If we render one theme by default and then change to a dark theme based on the user setting after hydration, there will definitely be a flash.
My proposal is to combine the light scheme and dark scheme into one theme. The scheme to display is determined by prefer-color-scheme
by default, but can be explicitly specified through html classes after hydration.
In other words, we split the concept of color scheme and theme. A theme consists of two color schemes: light and dark.
By doing so, we can make sure the color scheme of the first screen matches the user's system setting. If the user has explicitly specified a color scheme that doesn't match the system setting, we can then change the theme after the hydration. There will still be a flash in this case, but at least the first screen matches the system setting.
from ng-doc.
Switching to the dark theme by default still doesn't solve the problem. Before transitioning to SSR, the necessary theme was loaded via HTTP during the application initialization stage, and there was no flash. Now, it occurs more because the browser first renders what the server sends and then executes scripts. Therefore, if, for example, you move this logic into a separate script and include it in index.html
, there won't be any flash.
So I think the only solution could be integrating a script inside index.html
that sets the required theme, similar to what angular.dev does. But anyways, I'll consider this and look for solutions that would fix this flash.
from ng-doc.
Would you like me to create a new ticket for that?
from ng-doc.
Would you like me to create a new ticket for that?
There's no need for that, I'll do everything when I start working on the #126
from ng-doc.
Related Issues (20)
- [Feature] Remove Google Fonts HOT 4
- [Bug] ng-doc.routing.ts incorrect generated import HOT 10
- [Bug] input aliasing decorator selector not rendered correctly HOT 4
- [Feature] Support template variables for inputs HOT 11
- [Bug] hidden: true in NgDocPage-Config does not avoid displaying a component in the navigation. HOT 7
- [Bug] Table of contents link does not work properly with basehref HOT 4
- [Bug] Unable to leverage Keywords to create custom links in a reusable macro template HOT 8
- [Feature] Unable to leverage Custom Angular Components in the Markdown file HOT 3
- Support for Mermaid HOT 7
- [Bug] Unable to build docs when Playground refers components from angular library HOT 3
- [Bug] Extra /docs is introduced in the home icon of the breadcrumb during configuration of NgDoc route prefix HOT 4
- [Bug] Unable to display demo details of the components from angular library HOT 3
- [Query] Is it possible to import macros from angular library? HOT 4
- [Bug]Unable to customize the title of the API page HOT 1
- [Bug] The id of the html header is not serialized HOT 2
- Support for native i18n / $localize + localized markdown HOT 3
- [Feature] Demo Pane viewport and theme support
- [Feature] Custom Tabs in Demo HOT 4
- [Feature] Display Component Properties in Component Tabs and on Page
- [Bug] Configure Home icon route path of breadcrumb
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ng-doc.