-
-
Notifications
You must be signed in to change notification settings - Fork 602
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
Dark mode breaks Tailwind styling in some situations since NiceGUI 2.0 #3753
Comments
further updates: I still don't really understand how Tailwind does this, but I can confirm that the However, weirdly enough, in NiceGUI 2.1, if I change |
It seems plausible that it might be a bug in Vue? I don't know what is responsible for asking Tailwind to actually update the CSS. I don't see anything in NiceGUI that looks like it's involved. |
final note for the evening: I do see that the docs call out some specific Quasar+Tailwind incompatibilities with Button. I have confirmed that if there's a Quasar class applied (e.g. But I have been seeing this behavior with the Tailwind classes |
This morning, I think this must all be happening via the Tailwind CDN - NiceGUI is embedding Tailwind directly, and so it runs without a build/compile-time step. And yet, somehow, this new version of Tailwind is less consistent in NiceGUI 2.x than it was in 1.x - it misses "more" events than it used to, leading to missing CSS and broken pages. I can readily imagine this might be something that NiceGUI itself has very little control over. And yet, apparently the newer version of Tailwind is somehow worse than what was being packaged before. I am going to start looking for workarounds and I'll report back if I come up with anything. |
I've confirmed by setting a breakpoint on the Is there any chance that this has something to do with the order in which the Tailwind CDN/JS loads, as compared to the rest of the NiceGUI application? I wonder if they're simply not getting their MutationObserver registered early enough to catch the initial HTML being emitted by NiceGUI? |
Okay, I can confirm that simply by swapping out the newer version of Tailwind (3.4.5) for the older one from NiceGUI 1.4.x (3.3.2), the bad behavior goes away. I did this by copying My width and color classes are now being applied correctly in my more complex application. I am going to write up an issue for Tailwind, because what I'm seeing by stepping through the minified JS is that they've got a Set of known classes that already contains the classes that NiceGUI put into the HTML, but the corresponding CSS is not generated. Hence the odd behavior around how I can add new classes, see those styles generated, but then reverting back to the old HTML classes does not properly generate the previously missing classes. Once missed the first time, they are never generated by Tailwind even though the I might play around with even newer versions of Tailwind to see if any of them fix the issue. I somewhat doubt it, but you never know. :) |
Maybe you can help me figure out... it seems like the Tailwind 3.3.2 packaged by NiceGUI 1.4.x is not the same as what you can download from their CDN. And in fact any version that I download from their CDN exhibits the same 'broken' behavior. So I can't exactly post an issue over there yet, because I'm not sure what versions I'm actually dealing with. |
here's my post over there. I'm struggling to wrap my head around their behavior, which seems 'wrong', but also how y'all could have such a different-looking minified Tailwind JS file compared to what their CDN offers for 3.3.2. Maybe they've just changed how they're minifying it? |
Hi @petergaultney, Thanks for the thorough investigation! What a journey! By upgrading from TailwindCSS 3.2.0 to 3.4.10 in NiceGUI 2.0.0 we expected some minor hiccups, but not such fundamental styling issues. Even though they added some new classes, existing ones shouldn't break. Unfortunately, I can't reproduce the problem. A button like But I remember some trouble when upgrading the Tailwind dependency in PR #3654. It introduced layout problems, e.g. related to the resizing behavior of This might be related to your problem, since it is also a kind of timing issue. Another thing I remember: While debugging the EChart layouting problem, I tried switching between Tailwind versions and noticed that I couldn't reproduce the Tailwind version included in NiceGUI 1.4.x - exactly like you're reporting. It's still unclear to me why the minified files differ. Maybe Tailwind re-packaged (and re-uploaded!?) the files for some reason, or we got it from another source when releasing NiceGUI 1.4.0 in October 2023. But I couldn't find any information about it. So I hope we can find a reproduction and maybe a way to improve the reliability again. And maybe the Tailwind community can help. |
@petergaultney could you try to create a minimal reproducible example which breaks the colors? |
Yeah, right now I simply can't reproduce a minimal reproduction for colors. But Tailwind is essentially broken everywhere in our app, unless I revert to the old version that was specifically packaged with NiceGUI 1.4.x. One of our developers has further noted that by loading the parts of our UI that use Tailwind asynchronously (i.e. having them behind a nested I wish I were seeing any sort of engagement with my question over on Tailwind's page. One of their developers would likely have an immediate guess about what's happening, but so far I've not managed to trace their code down far enough to make sense of it (and I can't find the relevant original source code in order to unminify it either, which makes for some fairly painful reverse-engineering). |
Sometimes it's really hard to find a minimal reproduction. You could try to remove code from your productive system until the error disappears. This takes time because the removal steps between restarts and checks should not be to big but will bring you closer to a situation where the error still happens. |
After debugging this myself I found a minimal reproducible example. It looks to be a weird case where we set Note that the only case where the tailwind styling is not applied/generated is when from nicegui import ui
def render_total_count(total: int) -> None:
with ui.card().classes("w-full v-26 items-center").props("bordered"):
ui.label("Total Count").classes("text-3xl")
ui.separator()
ui.label(str(total)).classes("text-2xl")
@ui.page("/")
def index() -> None:
dark_mode = ui.dark_mode(True)
with ui.column().classes("w-full"):
render_total_count(50)
if __name__ in {"__main__", "__mp_main__"}:
ui.run(
dark=None,
) |
Oh wow, thanks @jdoiro3! Combining from nicegui import ui
ui.dark_mode(True)
ui.label('This should be bordered').classes('border')
ui.run(dark=None) With |
Apparently there have been changes to Tailwind's dark mode configuration in 3.3 and 3.4: To verify dark mode, we need to make sure every At the moment it looks like we might need to re-implement the whole dark mode integration, maybe based on |
Description
We upgraded from NiceGUI 1.4.30 to 2.1.0, and a lot of our CSS styling broke. We think it mostly has to do with tailwind classes somehow no longer being present/applied. I have narrowed it down to the 1.4.37 -> 2.0.0 upgrade by installing those versions specifically.
Systems affected are various, including multiple developer Mac laptops and our Linux-based deployment.
Screenshots, before and after the upgrade:
(expected layout, which we get in 1.4.37 and earlier)
(what we see in 2.0)
The relevant code, which was unchanged:
The text was updated successfully, but these errors were encountered: