Repository navigation
fix: resolve relative url() in style blocks and reject @import (#153) - #198
Merged
Merged
Conversation
) The Vite plugins served each component's extracted `<style>` CSS under a `\0`-prefixed virtual id. Vite resolves relative CSS references against the module id's directory, which then began with `\0` and did not exist, so a relative `@import` failed the build with ENOENT and a relative `url()` stayed unresolved. Use the component path plus the style query as the id, like Vue and Svelte style blocks, so references resolve from the component's directory in dev and builds. Vite now finds the CSS module under the component file on hot update, so the plugins skip adding it again when it is already listed. Add a shared build and dev-server harness and cover all five Vite plugins. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The compiler scopes only the rules written in a `<style>` block and passed `@import` through, so the bundler inlined the imported rules unscoped and they applied to the whole page. That defeats scoped style blocks, where `:global` is the explicit escape hatch. Report `@import` as the `tsrx-css-import` diagnostic (`CSS_IMPORT`) during style analysis, at the rule's position, for standalone, assigned, head, and resource blocks. Editors collect it like the other style diagnostics. Drop `@import` from the Vite reference fixture so it covers relative `url()` only, and document the rule in the specification, llms.txt, the core README, and the agent rules. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ng (#153) `@import` is only valid at the top level of a stylesheet, so scanning the style block's top-level rules is enough; the extra walk over every sheet is not needed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rts (#153) Name both routes to global CSS in the message and docs: `:global` in the block, or a JavaScript `import './global.css'`, which the bundler adds to the page unscoped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 23, 2026
This was referenced Sep 28, 2026
This branch was successfully deployed
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.
Fixes #153.
Problem
The issue reports two failures with relative references in a component's
<style>block under Vite:url(./asset.svg)stayed unresolved and Vite printed a warning.@import "./shared.css"failed the build with[postcss] ENOENT.Both came from the virtual module id: each Vite plugin served the extracted CSS as
\0/abs/App.tsrx?tsrx-css&lang.css. Vite's CSS plugin resolves relative references against the id's directory, which began with\0and wasn't a real path. The issue reported this for Hono, but the React, Preact, Solid, and Vue Vite plugins build the same id. The Rspack, Turbopack, and Bun plugins already use the component's real path.Looking at
@importmore closely showed a bigger problem than the resolution failure. The compiler scopes only the rules written in the block and passes@importthrough untouched. The bundler then inlines the imported file after scoping, so its rules come out unscoped and apply to the whole page. That defeats scoped style blocks, where:globalis the explicit escape hatch. So this PR rejects@importinstead of making it work.Changes
Vite plugins (patch): the stylesheet id is now the component path plus the style query, with no
\0. Vue's and Svelte's style blocks use the same form. Relativeurl()now resolves from the component's directory in builds and invite dev. During hot updates, Vite now lists the CSS module under the component's file, so the plugins no longer add it a second time. The React plugin's publishedresolveId/loadtypes drop the\0from their overloads.Core (minor, language removal):
@importin a<style>block is the newtsrx-css-importdiagnostic (DIAGNOSTIC_CODES.CSS_IMPORT). It's reported during style analysis at the rule's position, for standalone, assigned,<head>, and resource blocks, and in any case (@IMPORT). Only top-level rules are checked, since@importis only valid there. Editors collect it like the other style diagnostics. The message points to assigned blocks withapplyfor shared scoped styles, and, for global CSS, to:globalor a JavaScriptimport './global.css'. A plain-TSX<style>{css}</style>is an ordinary element and isn't checked.Docs: the spec's style constraints (prose and the diagnostics block),
llms.txt, the core README, and the RuleSync agent rules, with generated files and the MCP docs index regenerated.Tests
@tsrx/core/test-harness/css-references. It writes a component in a subdirectory whose<style>usesurl(./asset.svg), then either runs a Vite library build or starts a Vite dev server and fetches the component and its stylesheet module./components/Styled.tsrx?…&lang.css. All of them fail without the plugin change.@importform, multiple rules in one block, cases that must not be reported, and strict mode throwing a codedCompileError.\0id.ssrLoadModuleworks for Hono and React, and dev HMR picks up<style>edits on all five plugins.Commands run:
pnpm vitest runover the core analyze/utils, target compiler, runtime, vite-plugin,tsrx-vite, language-server, MCP, and website projects (all pass),pnpm typecheck,pnpm format:check, andpnpm changeset:check.Follow-up
Ripple's compiler lives in
Ripple-TS/ripple. If it runs the core style analysis, it picks up the new error on the next core bump. Otherwise it needs its own check.🤖 Generated with Claude Code
Note
Medium Risk
Adds a breaking compile error for
@importin<style>blocks (minor core bump) and changes virtual CSS module ids across all Vite plugins, which could affect custom tooling that assumed\0-prefixed ids.Overview
Fixes scoped
<style>behavior under Vite and closes a scoping hole for@import.Vite plugins (React, Preact, Solid, Vue, Hono): Extracted component CSS is no longer registered with a
\0-prefixed virtual id. The stylesheet module id is now the component file path plus the existing style query (e.g.?tsrx-css&lang.css), so Vite resolves relativeurl()(and@importpaths) from the component’s directory in dev and production. HMR lookup uses the same id; plugins avoid duplicating the CSS module when Vite already lists it.Core (minor):
@importat the top level of a scoped<style>body is a compile errortsrx-css-import(DIAGNOSTIC_CODES.CSS_IMPORT), with source positions on each import rule. Imported sheets would not be scoped and could leak globally; the message points to assigned blocks +applyfor shared scoped CSS and to JSimport './global.css'or:globalfor global styles.Tooling & docs: Spec,
llms.txt, agent rules, MCP style docs, and README list the new diagnostic. A sharedtest-harness/css-referencesfixture exercises build + dev URL resolution across Vite plugins; core analysis tests cover@importreporting.Reviewed by Cursor Bugbot for commit 509e8f1. Bugbot is set up for automated code reviews on this repo. Configure here.