-
Notifications
You must be signed in to change notification settings - Fork 358
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
fix: compact schema missing css field #1179
Conversation
修复 schema 缺少 css 字段时出码 style 中会包含 undefined 的 bug
WalkthroughThe change updates the Changes
Sequence Diagram(s)sequenceDiagram
participant C as Caller
participant G as generateStyleTag
C->>G: Call generateStyleTag(css)
alt css is defined
G-->>C: Return style tag with provided CSS
else css is falsy
G-->>C: Return style tag with empty string
end
Suggested labels
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 ESLint
packages/vue-generator/src/generator/vue/sfc/generateStyle.jsOops! Something went wrong! :( ESLint: 8.57.1 Error: Cannot read config file: /packages/vue-generator/.eslintrc.cjs
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/vue-generator/src/generator/vue/sfc/generateStyle.js (1)
16-16
: The fix for undefined CSS in style tag looks good.The addition of the fallback to an empty string (
css || ''
) ensures that the generated style tag will always contain valid content, even when the CSS field is missing from the schema. This directly addresses the issue mentioned in the PR where the tag was outputting "undefined".Additionally, consider adjusting the spacing in the style tag. The current template literals add extra spaces after the opening style tag and before the closing tag, which might not be desirable for all CSS content:
- return `<style ${langDesc} ${scopedStr}> ${css || ''} </style>` + return `<style ${langDesc} ${scopedStr}>${css || ''}</style>`
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/vue-generator/src/generator/vue/sfc/generateStyle.js
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: push-check
🔇 Additional comments (1)
packages/vue-generator/src/generator/vue/sfc/generateStyle.js (1)
1-2
: Consider adding a default for the schema parameter.The function currently handles the case when the
css
property is missing fromschema
, but it doesn't handle the case whenschema
itself is undefined or null. Consider adding a default value for theschema
parameter to make the function more robust:- export const generateStyleTag = (schema, config = {}) => { + export const generateStyleTag = (schema = {}, config = {}) => { const { css } = schema
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
兼容 schema 中 css 字段缺失时,出码成
<style scoped>undefined</style>
的 bug。What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit