fix(core): support media queries and nested selectors inside templates - #163
Open
richard-grosjean wants to merge 1 commit into
Open
fix(core): support media queries and nested selectors inside templates#163richard-grosjean wants to merge 1 commit into
richard-grosjean wants to merge 1 commit into
Conversation
`parseTemplates` re-implements template→CSS rendering and diverged from the
normal style parser in two ways, so media queries inside a `defineTemplates`
node never worked:
1. It treated *every* object-valued key as a nested template path segment. A
media query such as `'@largeMobileDown': { … }` in a leaf was therefore
dash-cased into the class name (`.text-style-…-large-@large-mobile-down`)
with no `@media` wrapper, and was never composed onto any element.
2. It never forwarded the config to `parseAndJoinStyles`, so even a media query
inside a rich node's `base` was emitted with its *named* query unresolved
(literal `@largeMobileDown { … }` instead of `@media (max-width: 960px)`).
Fix:
- Add `isStyleKey` (keys starting with `@`, `&` or `:`) and route those objects
to the style parser instead of recursing them as template paths — in leaves,
in rich-node bodies, and in the token/variant-map walkers (so they no longer
leak into generated template token types).
- Forward the resolved config from `SaltyCompiler` through `parseTemplates` to
`parseAndJoinStyles`, with template-token expansion disabled, so named media
queries / modifiers / tokens resolve in templates exactly as in component
styles.
Adds tests covering a media query in a leaf, named-query resolution via config,
and a media query in a rich node base.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
Just noticed that I could just have used the base/'at-mediaQuery' setup instead of relying on this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Media queries (and nested selectors / pseudos) declared inside a
defineTemplatesnode never work. Given:the generated
_templates.csscontains:— no
@mediawrapper, and the bogus class is never composed onto any element, so the responsive override is silently dead.Root cause
parseTemplates(libs/core/src/parsers/parse-templates.ts) re-implements template→CSS rendering and diverges from the normal style parser in two ways:'@largeMobileDown': { … }is an object, so it gets recursed as a path and dash-cased into the class name, with no@mediawrapping.getTemplateClasses()only walks the declared path (heading.large), so that class is never applied either.parseAndJoinStyles. So even when a query lives in a rich node'sbase(where the object is passed to the parser), the named query isn't resolved — it's emitted as a literal@largeMobileDown { … }instead of@media (max-width: 960px).By contrast, normal component styles go through
parseStyleswith the config, which handles@media/named queries/modifiers correctly.Fix
isStyleKey— keys starting with@,&or:are CSS constructs for the current node, not template paths. Route them to the style parser instead of recursing:base),isChildEntry/ the token & variant-map walkers, so they no longer leak into generated template token types.SaltyCompiler.generateCssthroughparseTemplatesintoparseAndJoinStyles, withomitTemplatesenabled (template definitions are literal styles and shouldn't recursively expand other templates). Named media queries, modifiers and tokens now resolve in templates exactly as in component styles.Tests
Added three cases to
parse-templates.spec.ts:@media, kept on the leaf class, not leaked into the class name;base→ wrapped correctly.nx run core:test(vitest,libs/core/src): 23 files / 449 tests pass (4 existing template tests + 3 new). Typecheck oflibs/coreis clean.No behavior change for templates without
@/&/:keys.