-
-
Notifications
You must be signed in to change notification settings - Fork 169
Fix CSS import queries (?url, ?inline, ?raw) being incorrectly collected in RSC plugin #579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { describe, expect, test } from 'vitest' | ||
|
||
/** | ||
* Check if a CSS import ID has special queries that should be excluded from CSS collection. | ||
* These queries transform CSS imports to return different data types rather than actual CSS to be linked. | ||
*/ | ||
function hasSpecialCssQuery(id: string): boolean { | ||
try { | ||
const url = new URL(id, 'file://') | ||
return ( | ||
url.searchParams.has('url') || | ||
url.searchParams.has('inline') || | ||
url.searchParams.has('raw') | ||
) | ||
} catch { | ||
// If URL parsing fails, check with simple string matching as fallback | ||
return id.includes('?url') || id.includes('?inline') || id.includes('?raw') | ||
} | ||
} | ||
|
||
describe('hasSpecialCssQuery', () => { | ||
test('should return true for CSS imports with ?url query', () => { | ||
expect(hasSpecialCssQuery('/path/to/style.css?url')).toBe(true) | ||
expect(hasSpecialCssQuery('/path/to/style.css?url&other=param')).toBe(true) | ||
expect(hasSpecialCssQuery('/path/to/style.css?other=param&url')).toBe(true) | ||
}) | ||
|
||
test('should return true for CSS imports with ?inline query', () => { | ||
expect(hasSpecialCssQuery('/path/to/style.css?inline')).toBe(true) | ||
expect(hasSpecialCssQuery('/path/to/style.css?inline&other=param')).toBe( | ||
true, | ||
) | ||
expect(hasSpecialCssQuery('/path/to/style.css?other=param&inline')).toBe( | ||
true, | ||
) | ||
}) | ||
|
||
test('should return true for CSS imports with ?raw query', () => { | ||
expect(hasSpecialCssQuery('/path/to/style.css?raw')).toBe(true) | ||
expect(hasSpecialCssQuery('/path/to/style.css?raw&other=param')).toBe(true) | ||
expect(hasSpecialCssQuery('/path/to/style.css?other=param&raw')).toBe(true) | ||
}) | ||
|
||
test('should return false for normal CSS imports', () => { | ||
expect(hasSpecialCssQuery('/path/to/style.css')).toBe(false) | ||
expect(hasSpecialCssQuery('/path/to/style.css?t=123456')).toBe(false) | ||
expect(hasSpecialCssQuery('/path/to/style.css?other=param')).toBe(false) | ||
}) | ||
|
||
test('should handle complex URLs with multiple parameters', () => { | ||
expect(hasSpecialCssQuery('/path/to/style.css?t=123&url&v=1')).toBe(true) | ||
expect(hasSpecialCssQuery('/path/to/style.css?t=123&inline&v=1')).toBe(true) | ||
expect(hasSpecialCssQuery('/path/to/style.css?t=123&raw&v=1')).toBe(true) | ||
expect(hasSpecialCssQuery('/path/to/style.css?t=123&other=param&v=1')).toBe( | ||
false, | ||
) | ||
}) | ||
|
||
test('should handle absolute URLs', () => { | ||
expect(hasSpecialCssQuery('http://localhost:3000/style.css?url')).toBe(true) | ||
expect(hasSpecialCssQuery('http://localhost:3000/style.css?inline')).toBe( | ||
true, | ||
) | ||
expect(hasSpecialCssQuery('http://localhost:3000/style.css?raw')).toBe(true) | ||
expect(hasSpecialCssQuery('http://localhost:3000/style.css?t=123')).toBe( | ||
false, | ||
) | ||
}) | ||
|
||
test('should handle file URLs', () => { | ||
expect(hasSpecialCssQuery('file:///path/to/style.css?url')).toBe(true) | ||
expect(hasSpecialCssQuery('file:///path/to/style.css?inline')).toBe(true) | ||
expect(hasSpecialCssQuery('file:///path/to/style.css?raw')).toBe(true) | ||
expect(hasSpecialCssQuery('file:///path/to/style.css?t=123')).toBe(false) | ||
}) | ||
}) |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove trivial unit tests. add e2e instead by updating
examples/basic
ande2e/basic.test.ts
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! I've removed the trivial unit tests and replaced them with e2e tests. Added CSS query test components to
examples/basic
and comprehensive e2e tests inbasic.test.ts
that verify both the functional behavior and SSR CSS collection. (0f6af41)