refactor: rename misleading variables and apply targeted code quality improvements#236
Conversation
- Rename `options` state to `previewCode` in Playground.tsx for clarity - Add ITEM_POSITION_H/ITEM_POSITION_V constants in chart-line.tsx - Fix gradient area color to use last colorStopsData color instead of colorPrimary - Add NaN check for width/height in svg.ts getExportViewBox - Add braces around single-statement if in embedIcons - Add empty id guard in collectDefElements - Replace simple regex CSS escape fallback with full CSS.escape algorithm - Remove redundant condition in search.ts loadSearchResource - Use charCodeAt comparison in getCommonPrefixLength for performance - Extract isBetterMatch helper function in templates/utils.ts Agent-Logs-Url: https://github.com/antvis/Infographic/sessions/289607cf-6b2e-4c1c-b79d-ec538a1b098c Co-authored-by: Aarebecca <25787943+Aarebecca@users.noreply.github.com>
…ator precedence - Move !id guard before visited.add() to prevent empty strings being added - Add parentheses around range checks in CSS escape fallback for correct precedence Agent-Logs-Url: https://github.com/antvis/Infographic/sessions/289607cf-6b2e-4c1c-b79d-ec538a1b098c Co-authored-by: Aarebecca <25787943+Aarebecca@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors state management in the Playground, enhances SVG export validation, and implements a comprehensive CSS escape fallback. It also optimizes template key matching and removes redundant resource loading logic. Review feedback identifies critical bugs in the CSS escape algorithm regarding leading digits and hyphen-digit sequences, which require hex-based escaping. Additionally, improvements are suggested to enhance performance by hoisting static constants and helper functions, and to remove a redundant SVG stop element.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #236 +/- ##
==========================================
+ Coverage 46.85% 50.55% +3.69%
==========================================
Files 342 343 +1
Lines 28417 28941 +524
Branches 2400 2698 +298
==========================================
+ Hits 13315 14631 +1316
+ Misses 15089 14297 -792
Partials 13 13
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Several small but meaningful issues across the codebase: a misleading state variable name, inconsistent gradient colors, missing NaN guards, a redundant code branch, and readability/performance gaps in utility functions.
dev/src/Playground.tsxoptions/setOptions→previewCode/setPreviewCode— the variable holds debounced code string, not optionssrc/designs/structures/chart-line.tsxITEM_POSITION_H/ITEM_POSITION_Vtyped constants (as const) for position literalscolorStopsData[last]?.color ?? colorPrimaryinstead of alwayscolorPrimary, matching the stroke gradient's behaviorsrc/exporter/svg.tsNumber.isNaNguards before> 0checks onparseAbsoluteLengthresults (returnsNaNfor invalid input)if (symbolElement)inembedIconsidguard beforevisited.add(id)to avoid polluting the visited setCSS.escapefallback with a spec-compliant implementation handling null chars, control chars, leading-digit/hyphen rules, and non-ASCII characterssrc/resource/loaders/search.tsif (mimeType === 'image/svg+xml' && format === 'svg' && isBase64)branch — it fell through to the identicalreturn loadImageBase64Resource(result)callsrc/templates/utils.tsgetCommonPrefixLength: switched from bracket indexing tocharCodeAtfor tighter inner-loop performanceisBetterMatch(...)helper fromfindClosestTemplateKeyto reduce nesting depthOriginal prompt