Instatic icon indicating copy to clipboard operation
Instatic copied to clipboard

Site Import: cross-page class-name collisions silently drop styles instead of resolving them

Open gaurangrshah opened this issue 4 months ago • 2 comments

Summary

When importing a multi-page static site where different pages independently define CSS classes with the same name but different declarations (common with Astro's per-route scoped CSS, but not Astro-specific — any static-site generator that doesn't globally namespace component classes will hit this), Site Import silently produces a style rule with an empty styles: {} object instead of either (a) keeping the first-seen declaration, (b) renaming the colliding class per source, or (c) surfacing it in the Conflicts step for the user to resolve.

The class name and its binding to the correct DOM nodes (classIds) import correctly — only the CSS declarations are lost. This means imported pages render with no styling for every collided class, silently, without any warning or error.

Repro

Site: a 13-page Astro static build (7 unique pages + 6 templated /services/* routes sharing one bundle), each page/bundle with Astro-scoped CSS (.className[data-astro-cid-XXXXXXXX]).

Example collision — hero__heading is declared independently in 3 different page bundles with genuinely different values:

/* about.sKbgvkNL.css */
.hero__heading[data-astro-cid-kh7btl4r]{font-size:clamp(2.5rem,6vw,4.25rem);line-height:1.04;letter-spacing:-.025em;color:#fff;text-wrap:balance;margin:0 0 var(--space-4)}

/* index.Y9HaA8pz.css */
.hero__heading[data-astro-cid-j7pv25f6]{font-size:clamp(2.5rem,6vw,4.25rem);line-height:1.04;letter-spacing:-.025em;color:#fff;text-wrap:balance;margin:0 0 var(--space-4)}

/* testimonials.CL9ktNOP.css */
.hero__heading[data-astro-cid-gx536xi6]{font-size:var(--font-size-3xl);line-height:1.1;letter-spacing:-.02em;color:var(--color-primary-800);text-wrap:balance;margin:0 0 var(--space-4)}

After Site Import (whole-folder drop, default "convert to editable rules" stylesheet mode), the resulting styleRules entry for hero__heading (and 224 other classes in this build) is:

{
  "id": "...",
  "name": "hero__heading",
  "kind": "class",
  "selector": ".hero__heading",
  "order": ...,
  "styles": {},
  "contextStyles": {}
}

classIds on the actual page nodes correctly point at this rule id — so the binding is right, the rule is just empty. Verified by direct inspection of site.styleRules in the SQLite settings_json blob.

Scope of impact

In this 350-custom-class import: 125 classes that were genuinely shared across all pages (identical name + declaration in every bundle, e.g. .section, .container from a common design-system stylesheet) imported correctly. 225 classes that were page-scoped/component-local (different declarations per page, same name) all ended up with empty styles: {}. That's roughly 2/3 of all custom classes lost in a real-world multi-page import.

Expected behavior

Per docs/features/site-import.md's own TL;DR: "What cannot be modeled: @layer, conditional local CSS @import, and arbitrary external @import — surfaced as warnings when the CSS engine exposes them, never silently dropped." This collision case isn't in that list, and unlike the documented exceptions, nothing was surfaced — no warning in the Review step (as far as the user could tell), nothing in server logs. The style loss was only discoverable by inspecting the raw DB.

Reasonable fixes, roughly in order of user-friendliness:

  1. Surface same-name-different-declaration collisions in the Conflicts step (the docs describe exactly this kind of per-class-name conflict UI already existing for within-file rename/overwrite/skip — this seems like it should be the same code path, just not triggering for the cross-file case where declarations differ).
  2. At minimum, don't silently zero out the losing side — keep the first-seen declaration rather than dropping it, so the visual result is "slightly wrong" instead of "completely unstyled."

Workaround used

Pre-processed the static build before import: for each page-scoped CSS bundle (excluding genuinely shared/common bundles), suffixed every class name with a short deterministic tag derived from the bundle's own build hash, and rewrote the corresponding class="..." tokens in that bundle's consuming HTML page(s). This makes every class name globally unique before Site Import ever sees it, sidestepping the collision entirely. Happy to share the script if useful as a reference, though obviously the real fix belongs in Site Import itself.

Environment

  • Instatic version: v0.0.11 (git tag), image ghcr.io/corebunch/instatic:latest
  • Deployment: self-hosted, Docker Compose, SQLite backend
  • Import method: whole-folder drop via Site Import modal, default per-stylesheet mode (convert to editable rules)

gaurangrshah avatar Jul 23 '26 21:07 gaurangrshah

A related case in the same conflict-resolution path: re-importing into a site that already has the classes, with Overwrite chosen, keeps the old declaration.

Steps (0.0.20, f92e8dc, local bun run start, SQLite):

  1. Import a static site whose stylesheet has .hero_subheading { color: var(--old-orange); }, and publish.
  2. Change that rule in the source to .hero_subheading { color: var(--color-accent-high-500); }. Leave the rest of the bundle the same.
  3. Import the same bundle again. In Conflicts, choose Overwrite all for page slugs, class names (734 conflicts) and design tokens. Import, then publish.

Expected: the published rule is the newly imported one, color: var(--color-accent-high-500).

Actual: the published style-*.css, and the live page's CSSOM, still have color: var(--old-orange) for .hero_subheading. Import completes with no warning. After a database reset (bun run db:drop -y), importing the same bundle fresh gives the new value, so the source bundle is correct and only the overwrite path keeps the old rule.

I didn't inspect site.styleRules directly, so I can't say whether the overwritten rule ends up with the old declarations or an empty styles object plus a leftover duplicate. Either way, Overwrite didn't replace the rule's declarations.

ehnruiz avatar Oct 10 '26 21:10 ehnruiz

Another data point for the collision against the existing site registry (0.0.21, Postgres, convert mode). It matches the Overwrite behaviour in the comment above.

The site already had .post-card from an earlier Automatic.css import (18 declarations, origin automatic.css). I then imported a second stylesheet with the theme's own definition of the same class:

.post-card { display: flex; flex-direction: column; align-items: center; box-sizing: border-box; position: relative; overflow: clip; /* ... */ }

Result after the import:

  • the registry still has exactly one .post-card, unchanged: no align-items, no box-sizing, origin still automatic.css;
  • no renamed class (no post-card-2);
  • no warning anywhere.

I did not record which resolution the Conflicts step applied, so I can't say whether it was the default or Overwrite. From reading conflicts.ts I would expect either an auto-renamed class (the documented default) or, for Overwrite, tx.overwriteStyleRule(existingRuleId, rule) replacing the declarations. I saw neither.

Workaround: add the missing properties to the existing class by hand. A visible warning in the Conflicts step ("N declarations of .post-card differ and will be ignored/replaced") would have saved a lot of time.

Amay66 avatar Oct 16 '26 08:10 Amay66