S
SolidJS2mo ago
zimo

Navigating through @solidjs/router doesn't load global app.css

When navigating from index to another route, the app.css doesn't persist as a <style> tag, despite being imported in the app.tsx file. Demo project: https://github.com/zimonitrome/solid_error_demo.git To reproduce: npm install, npm run dev, click "page 2" -> "home" -> "page 2" from the navigation links. Side question: Why are styles added twice? See second image. This seems like default Vinxi behavior.
No description
No description
18 Replies
zimo
zimo2mo ago
@Katja (katywings) do you know anything about this? You helped me out here: https://discord.com/channels/722131463138705510/1260841964857720833/1260841964857720833 Which fixed my previous problem which was very similar.
Katja (katywings)
There was a PR about this https://github.com/nksaraf/vinxi/pull/294. I guess it didn't fix all issues of this sort 🙈
GitHub
Build software better, together
GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects.
From An unknown user
From An unknown user
From An unknown user
zimo
zimo2mo ago
thank you so much 🙏 I was going a little crazy gonna try to comment on that PR/issue
Katja (katywings)
Youre welcome 😊, I hope we can solve the rest of these issues swiftly 😁
zimo
zimo2mo ago
Nice. I posted this even more simplified version of the problem here in the original issue thread: https://github.com/solidjs/solid-start/issues/1401#issuecomment-2233170499 Do you think this will be visible or should I create yet another issue? maybe @ryansolid could reopen the issue
ryansolid
ryansolid2mo ago
I talked to Nikhil about this a bit.. his reference counting approach doesn't work on the server which I believe is where the problem came in. It's related this issue right: https://github.com/nksaraf/vinxi/issues/318
GitHub
[BUGS] Styles in prod are injected twice and have wrong order · Iss...
The same styles are injected twice (into head and then into body). The styles are injected in incorrect order (in head they have correct order, and then in body incorrect):
ryansolid
ryansolid2mo ago
I think the decided solution was handle it in SolidStart and probably rip out this logic as it can't handle SSR properly anyway.
zimo
zimo2mo ago
I'm not entirely sure it's related but both are unexpected behavior. As long as you and Nikhil are aware of the problem then I'm happy :) It appears to only be a problem in dev anyway. It's just an inconvenience when debugging and implementing routing behaviors.
ryansolid
ryansolid2mo ago
Oh that issue suggests there is an issue in prod..
zimo
zimo2mo ago
to clarify: the duplicate CSS links are still a problem in prod, but the missing css links are not so my application works fine in prod, albeit with some overhead of duplicate links
ryansolid
ryansolid2mo ago
Ok can we talk about abou the missing ones then. I want to get what is going on. The reason we added the reference check stuff was styles were being added and then completely unloaded on navigation if the root and the page both imported. It would see that style for the page and remove it not realizing it was also being used by the root. Is this what you are seeing?
Katja (katywings)
For the duplicated entries in prod I explained the reasons in this comment: https://github.com/nksaraf/vinxi/issues/318#issuecomment-2188951604 (Duplicated CSS entries). The duplicated <style> entries in dev are a different issue I think, as @zimo mentioned :).
zimo
zimo2mo ago
It would see that style for the page and remove it not realizing it was also being used by the root. Is this what you are seeing?
No, not explicitly at least. I have an app.css which is only imported in app.tsx. App.tsx has a router to two pages: "index" ("localhost:3000/") & "page 2" ("localhost:3000/otherpage"). But the weird part is that it only happens when I import signals from other components (something I do very liberally). I tried to demonstrate it with this diagram from a minimal example:
No description
zimo
zimo2mo ago
The yellow boxes in the image are signals. When either of the two signals are NOT imported, the css is loaded as expected. I.e. if "ref1 or "ref2" in the image is broken, the problem disappears. So maybe what happens is that index.tsx loads compB.tsx which loads app.tsx and all along the way the app.css is seen by Vinxi as being imported by index.tsx. Hence why it gets removed when navigating to otherpage.tsx. Again, here is my comment on the GH issue: https://github.com/solidjs/solid-start/issues/1401#issuecomment-2233170499 I tried making an as minimal as possible project to demonstrate the problem: https://github.com/zimonitrome/solid_error_demo
ryansolid
ryansolid2mo ago
Yeah ok.. I see.. you are actually importing app.tsx from CompB which means that yes it would also get app.css I strongly recommend not exporting more than one thing from app or from page components.. Just pull into a shared location they both can grab from. In general I guess app being top level means it is everywhere anyway but we have no choice to assume that the CSS is needed again from there.. My guess is because this is over page boundaries Nikhil's approach to deduping didn't work.. Ours should
Want results from more Discord servers?
Add your server