Skip to content
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

replace custom class:list implementation with clsx #3935

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-steaks-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Replace custom class:list implementation with clsx package
1 change: 1 addition & 0 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"ast-types": "^0.14.2",
"boxen": "^6.2.1",
"ci-info": "^3.3.1",
"clsx": "^1.2.1",
"common-ancestor-path": "^1.0.1",
"debug": "^4.3.4",
"diff": "^5.1.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/runtime/server/hydration.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import clsx from 'clsx';
import type {
AstroComponentMetadata,
SSRElement,
SSRLoadedRenderer,
SSRResult,
SSRResult
} from '../../@types/astro';
import { escapeHTML } from './escape.js';
import { serializeProps } from './serialize.js';
import { serializeListValue } from './util.js';

const HydrationDirectives = ['load', 'idle', 'media', 'visible', 'only'];

Expand Down Expand Up @@ -86,7 +86,7 @@ export function extractDirectives(inputProps: Record<string | number, any>): Ext
}
} else if (key === 'class:list') {
// support "class" from an expression passed into a component (#782)
extracted.props[key.slice(0, -5)] = serializeListValue(value);
extracted.props[key.slice(0, -5)] = clsx(value);
} else {
extracted.props[key] = value;
}
Expand Down
12 changes: 5 additions & 7 deletions packages/astro/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import clsx from 'clsx';
import type {
APIContext,
AstroComponentMetadata,
Expand All @@ -6,27 +7,24 @@ import type {
Params,
SSRElement,
SSRLoadedRenderer,
SSRResult,
SSRResult
} from '../../@types/astro';

import { escapeHTML, HTMLString, markHTMLString } from './escape.js';
import { extractDirectives, generateHydrateScript } from './hydration.js';
import { createResponse } from './response.js';
import {
determineIfNeedsHydrationScript,
determinesIfNeedsDirectiveScript,
getPrescripts,
PrescriptType,
PrescriptType
} from './scripts.js';
import { serializeProps } from './serialize.js';
import { shorthash } from './shorthash.js';
import { serializeListValue } from './util.js';

export {
escapeHTML,
HTMLString,
markHTMLString,
markHTMLString as unescapeHTML,
markHTMLString as unescapeHTML
} from './escape.js';
export type { Metadata } from './metadata';
export { createMetadata } from './metadata.js';
Expand Down Expand Up @@ -545,7 +543,7 @@ Make sure to use the static attribute syntax (\`${key}={value}\`) instead of the

// support "class" from an expression passed into an element (#782)
if (key === 'class:list') {
const listValue = toAttributeString(serializeListValue(value));
const listValue = toAttributeString(clsx(value));
if (listValue === '') {
return '';
}
Expand Down
36 changes: 0 additions & 36 deletions packages/astro/src/runtime/server/util.ts

This file was deleted.

2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.