Skip to content

Commit 84b3781

Browse files
authored
fix(loading): consistent colors in loading screen (#6679)
**Problem:** Today if there is a difference between the system theme preferences and the Utopia theme preferences, at some point we get mixed colors in the loading screen. This happens because at first we can rely only on system preferences (React code was not loaded yet and we don't have user preferences), and only 1-2s into the loading we have the user preferences. **Fix:** All the colors now are consistent with the theme. We have two options when the system theme and the Utopia theme don't match: 1. continue with the theme that was displayed when the loading screen started (currently the theme from the system preferences since this is the only information we have) 2. switch the theme once we have the user preferences mid-way in the loading screen. this was not chosen by Mckayla. Once we'll be able to send this information from the server we can start with the Utopia preferred theme (have a class name on the body). **Manual Tests:** I hereby swear that: - [X] I opened a hydrogen project and it loaded - [X] I could navigate to various routes in Play mode
1 parent 9e99bae commit 84b3781

File tree

2 files changed

+42
-52
lines changed

2 files changed

+42
-52
lines changed

editor/src/components/editor/loading-screen.tsx

+1-16
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ import { getImportOperationTextAsJsx } from './import-wizard/import-wizard-helpe
44
import { getTotalImportStatusAndResult } from '../../core/shared/import/import-operation-service'
55
import type { TotalImportResult } from '../../core/shared/import/import-operation-types'
66
import type { Theme } from '../../uuiui'
7-
import { useColorTheme } from '../../uuiui'
87
import { getCurrentTheme } from './store/editor-state'
98
import ReactDOM from 'react-dom'
109

1110
export function LoadingEditorComponent() {
12-
const colorTheme = useColorTheme()
13-
1411
const currentTheme: Theme = useEditorState(
1512
Substores.theme,
1613
(store) => getCurrentTheme(store.userState),
@@ -131,25 +128,14 @@ export function LoadingEditorComponent() {
131128
hasMounted.current = true
132129
}
133130

134-
const themeStyle =
135-
currentTheme === 'dark'
136-
? `
137-
.editor-loading-screen { background-color: ${colorTheme.bg6.value} }
138-
.utopia-logo-pyramid.light { display: none; }
139-
.utopia-logo-pyramid.dark { display: block; }
140-
`
141-
: ''
142-
143131
return ReactDOM.createPortal(
144132
<React.Fragment>
145-
<style>{themeStyle}</style>
146-
<div className='progress-bar-shell' style={{ borderColor: colorTheme.fg0.value }}>
133+
<div className='progress-bar-shell'>
147134
<div
148135
className='progress-bar-progress animation-progress'
149136
style={{
150137
transform: 'translateX(-180px)',
151138
animationName: 'animation-keyframes-2',
152-
backgroundColor: colorTheme.fg0.value,
153139
}}
154140
></div>
155141
</div>
@@ -159,7 +145,6 @@ export function LoadingEditorComponent() {
159145
<li
160146
style={{
161147
listStyle: 'none',
162-
color: colorTheme.fg0.value,
163148
}}
164149
key={currentOperationToShow.id}
165150
>

editor/src/templates/index.html

+41-36
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,31 @@
3838
}
3939

4040
@scope (:root) to (#canvas-container) {
41+
body {
42+
/* handle system preferences and utopia theme */
43+
--theme-bg-color: white;
44+
--theme-fg-color: black;
45+
--theme-light-png-visibility: block;
46+
--theme-dark-png-visibility: none;
47+
}
48+
49+
@media (prefers-color-scheme: dark) {
50+
body:not(.utopia-theme-light) {
51+
--theme-bg-color: #1a1a1a;
52+
--theme-fg-color: white;
53+
--theme-light-png-visibility: none;
54+
--theme-dark-png-visibility: block;
55+
}
56+
}
57+
58+
/* utopia preferences should override system preferences */
59+
body.utopia-theme-dark {
60+
--theme-bg-color: #1a1a1a;
61+
--theme-fg-color: white;
62+
--theme-light-png-visibility: none;
63+
--theme-dark-png-visibility: block;
64+
}
65+
4166
body {
4267
margin: 0;
4368
font-size: 11px !important;
@@ -46,6 +71,8 @@
4671
outline: none;
4772
overscroll-behavior-x: contain;
4873
--loadscreen-accent: rgba(46, 255, 109, 0.5);
74+
background-color: var(--theme-bg-color);
75+
transition: background-color 0.1s ease-in-out;
4976
}
5077

5178
@keyframes animation-keyframes {
@@ -85,7 +112,8 @@
85112
flex-direction: column;
86113
align-items: center;
87114
justify-content: center;
88-
background-color: white;
115+
background-color: var(--theme-bg-color);
116+
transition: background-color 0.1s ease-in-out;
89117
z-index: 1000;
90118
}
91119

@@ -105,7 +133,8 @@
105133
}
106134

107135
.progress-bar-shell {
108-
border: 1px solid black;
136+
border: 1px solid var(--theme-fg-color);
137+
transition: border-color 0.1s ease-in-out;
109138
margin-top: 64px;
110139
width: 212px;
111140
height: 11px;
@@ -115,13 +144,13 @@
115144
}
116145

117146
.progress-bar-progress {
118-
background-color: black;
147+
background-color: var(--theme-fg-color);
148+
transition: background-color 0.1s ease-in-out;
119149
border-radius: 6px;
120150
height: 9px;
121151
}
122152

123153
.loading-screen-import-operations {
124-
color: black;
125154
height: 150px;
126155
overflow: hidden;
127156
width: auto;
@@ -136,11 +165,17 @@
136165
font-family: utopian-inter, 'sans-serif';
137166
}
138167

168+
.loading-screen-import-operations,
169+
.loading-screen-import-operations li {
170+
color: var(--theme-fg-color);
171+
transition: color 0.1s ease-in-out;
172+
}
173+
139174
.utopia-logo-pyramid.light {
140-
display: block;
175+
display: var(--theme-light-png-visibility);
141176
}
142177
.utopia-logo-pyramid.dark {
143-
display: none;
178+
display: var(--theme-dark-png-visibility);
144179
}
145180

146181
.loading-screen-wrapper {
@@ -149,36 +184,6 @@
149184
align-items: center;
150185
justify-content: center;
151186
}
152-
153-
@media (prefers-color-scheme: dark) {
154-
body {
155-
background-color: #1a1a1a;
156-
}
157-
158-
.editor-loading-screen {
159-
background-color: #1a1a1a;
160-
}
161-
162-
.loading-screen-import-operations,
163-
.loading-screen-import-operations li {
164-
color: white;
165-
}
166-
167-
.progress-bar-shell {
168-
border: 1px solid white;
169-
}
170-
171-
.progress-bar-progress {
172-
background-color: white;
173-
}
174-
175-
.utopia-logo-pyramid.light {
176-
display: none;
177-
}
178-
.utopia-logo-pyramid.dark {
179-
display: block;
180-
}
181-
}
182187
}
183188
</style>
184189
</head>

0 commit comments

Comments
 (0)