Skip to content

Flash on initial load on the web #597

Description

@florian-lefebvre

What happened?

On the web I'd expect Uniwind to work with CSS variables ootb. Currently it seems it still needs some internal state.

I have an inline script that sets .light or .dark so it happens instantly. But the theme is not updated until Uniwind.setTheme() is called just a bit later, which causes a flash.

This pattern works in e.g. Astro when dealing with Tailwind so I assume some of the implementation here is not CSS only on the web. I know native have different constraints so this is just about web (+ a flash there does not occur on android).

Relevant files:

Steps to Reproduce

  1. Clone the code from the repository
  2. From the root, run pnpm i --frozen-lockfile
  3. From the root, run pnpm add web
  4. Open the browser
  5. In the top right, switch to dark mode (icon should be a moon)
  6. Refresh the page

Things to observe:

  1. If you open the element inspector, you can see the .dark class is applied immediatly on reload
  2. You can see a flash, i.e. a delay until dark theme is actually applied

Snack or Repository Link

https://github.com/florian-lefebvre/expo-starter/tree/fix/theme-flash

Uniwind version

1.10.0

React Native Version

0.86.0

Platforms

Web

Expo

Yes

Additional information

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions