Dev: a stylesheet shared by the entry and a lazy component moves after the lazy component's styles
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 3/5
- Temps estimé
- Une demi-journée
- Accessibilité débutants
- 62/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- css, javascript, typescript
- Domaine
- build-system, frontend
Piste de recherche
The dedupe logic is in devStylePatch in src/dev-manifest.ts, on the line that picks ssr from o and el by data-asset. Reproduce with the issue's App/Button/Page files and check the link tags in the hydrated head. Done means .corner resolves to absolute in dev, the stylesheet order matches vite build, and editing button.css still hot-updates while the page is open.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
In start-mode dev, a stylesheet that both the entry graph and a lazy component import ends up after the lazy component's own stylesheets. Production keeps it before them. Rules of equal specificity then resolve the other way in dev: a lazy page's override of a shared component's style loses.
Versions: @solidjs/[email protected], [email protected], @solidjs/[email protected], [email protected].
Reproduction
// vite.config.ts
import { defineConfig } from 'vite';
import solid from '@solidjs/vite-plugin';
export default defineConfig({
plugins: [solid({ start: { app: 'src/App.tsx' }, ssr: true })],
});
// src/App.tsx
import { lazy, Loading } from 'solid-js';
import { Button } from './Button';
const Page = lazy(() => import('./Page'));
export default function App() {
return (
<main>
<Button>Header button</Button>
<Loading>
<Page />
</Loading>
</main>
);
}
// src/Button.tsx
import type { JSX } from 'solid-js';
import './button.css';
export function Button(props: { class?: string; children: JSX.Element }) {
return <button class={`button ${props.class ?? ''}`}>{props.children}</button>;
}
// src/Page.tsx
import { Button } from './Button';
import './page.css';
export default function Page() {
return (
<div class="panel">
<Button class="corner">Copy</Button>
</div>
);
}
/* src/button.css */
.button {
position: relative;
}
/* src/page.css */
.panel {
position: relative;
height: 200px;
border: 1px solid;
}
/* Same specificity as .button, so it wins only when page.css comes after button.css. */
.corner {
position: absolute;
top: 8px;
right: 8px;
}
Run vite, open the page, and wait for hydration. "Copy" stays in the normal flow instead of the panel's top right corner. vite build + vite preview renders it in the corner.
| style tags in the server HTML | style tags after hydration | .corner |
|
|---|---|---|---|
| dev | button.css, page.css, button.css |
page.css, button.css |
position: relative |
| build | Button-*.css, Page-*.css |
Button-*.css, Page-*.css |
position: absolute |
Cause
The dev shell carries button.css twice, both marked data-asset. The SSR runtime renders the lazy component's styles (button.css, page.css), and the handler then injects the entry graph's styles (button.css again) before </head>.
devStylePatch (src/dev-manifest.ts) dedupes the two by data-vite-dev-id. It removes o, the tag found by querySelectorAll, whenever o is data-asset:
var ssr=o.hasAttribute("data-asset")?o:el.hasAttribute("data-asset")?el:null;
When both twins are SSR'd, the observer handles the later tag as el, so o is the earlier one and it is removed. The copy that survives sits after page.css.
Suggested fix
When both twins are SSR'd, drop the later one, so the stylesheet keeps the first position the shell gave it:
var ssr=o.hasAttribute("data-asset")&&el.hasAttribute("data-asset")?(o.compareDocumentPosition(el)&4?el:o):o.hasAttribute("data-asset")?o:el.hasAttribute("data-asset")?el:null;
With that line patched into the repro's copy of the plugin, the hydrated order is button.css, page.css and .corner is absolute, as in the build. Editing button.css with the page open still hot-updates it.
Not emitting entry styles that the shell already carries would fix it as well. Moving the entry styles ahead of the lazy ones does not: in the larger app where I first saw this, the shared stylesheets still ended up after the lazy ones.
- Langage dominant
- TypeScript
- Étoiles
- 522
- Forks
- 73
- Merge moyen
- 1 j 4 h
- PR mergées (30 j)
- 35
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de solidjs/solid-vite-plugin
-
Test environment detection doesn't consider Vitest workspacesPeut-être pris @carloitaben l’a pris il y a 57 jours. Ouverte1.x
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
solidjs/solid-vite-plugin#205 · 1 commentaire · 2 réactions ·
Les mainteneurs répondent en général sous 1 jour
-
serverFunctions.components (dev): server-functions client is duplicated when @solidjs/web is in optimizeDeps.exclude, so post-boot server components resolve to undefinedPeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 58/100
solidjs/solid-vite-plugin#428 ·
Les mainteneurs répondent en général sous 1 jour
-
[3.0.0-next.50 / next] Dev with a host-owned SSR environment: the first server-function call after startup, a restart or a new "use server" file waits a fixed 1 sPeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 58/100
solidjs/solid-vite-plugin#427 ·
Les mainteneurs répondent en général sous 1 jour
-
[3.0.0-next.50 / next] SSR build: the $$moduleUrl export added to a Worker main module stops workerd from startingPeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 3/5 Une demi-journée Accessibilité débutants 55/100
solidjs/solid-vite-plugin#420 ·
Les mainteneurs répondent en général sous 1 jour
-
Client setup seam: run app code before the generated entry's hydrate (start.clientSetup)Peut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
solidjs/solid-vite-plugin#419 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de solidjs/solid-vite-plugin
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
ccch1mneyyy/dsh-TUI#1631 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
MiniMax-AI/minimax-code#507 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
-
Transient OAuth login failure persists in getLoginStatus and masks active account in dashboardPeut-être à nouveau libre Une pull request pour cette issue a été fermée sans être fusionnée. Ouverteaccount-pool bug gui
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
lidge-jun/opencodex#7378 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Admin search throws for permissions added through Admin.generalIndexItems('permissions', ...)Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
Les mainteneurs répondent en général sous 1 jour