fix: improve handling of lines starting with a kanji (#3821)#3822
fix: improve handling of lines starting with a kanji (#3821)#3822d0gkiller87 wants to merge 2 commits intospicetify:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughUpdated lyric text handling: three memoized page components now use type-aware normalization when deriving comparison text; ruby-to-React conversion no longer inserts an empty initial child when the pre-ruby segment is empty. Changes
Sequence Diagram(s)(omitted — changes are focused, not introducing new multi-component control flow) Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
CustomApps/lyrics-plus/Utils.js (1)
178-186:⚠️ Potential issue | 🟡 MinorFix biome formatting failure and apply the same empty-string guard to the trailing segment.
Two things on this block:
- CI is failing on biome formatting for this file. The new
ifuses single quotes and omits braces, which is inconsistent with the rest of the file (tabs + double quotes + braced bodies). Reformatting should clear the pipeline failure.- The symmetric case on line 185 —
rubyElems[i].split("</ruby>")[1]— pushes an empty string when a line ends with</ruby>(i.e. no trailing text after the last ruby). That yields the same kind of empty leading/trailing child inp1.props.childrenthat the new guard is avoiding at the start, sobelowTxtextraction inPages.jscan still misbehave depending on which end is affected. Worth guarding both ends the same way.Proposed fix
- if (rubyElems[0] !== '') - reactChildren.push(rubyElems[0]); + if (rubyElems[0] !== "") { + reactChildren.push(rubyElems[0]); + } for (let i = 1; i < rubyElems.length; i++) { const kanji = rubyElems[i].split("<rp>")[0]; const furigana = rubyElems[i].split("<rt>")[1].split("</rt>")[0]; reactChildren.push(react.createElement("ruby", null, kanji, react.createElement("rt", null, furigana))); - - reactChildren.push(rubyElems[i].split("</ruby>")[1]); + const trailing = rubyElems[i].split("</ruby>")[1]; + if (trailing !== "") { + reactChildren.push(trailing); + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@CustomApps/lyrics-plus/Utils.js` around lines 178 - 186, The if statement and trailing push in the loop need to match file formatting and avoid empty-string children: change the new guard to use the file's style (tabs, double quotes, braced body) and add a symmetric empty-string check before pushing the trailing segment (the result of rubyElems[i].split("</ruby>")[1]); locate the block using symbols rubyElems, reactChildren and react.createElement and ensure you only push the trailing part when it's not "" so both leading and trailing empty children are prevented.
🧹 Nitpick comments (1)
CustomApps/lyrics-plus/Pages.js (1)
311-320: DeduplicatebelowTxt/belowOriginextraction across the three pages.The same nested-ternary for
belowTxtis repeated verbatim at lines 313-318, 642-647, and 726-731, and thebelowOriginexpression on line 312 (and 641, 725) still uses the oldtext?.props?.children?.[0]pattern without the new "only if string" guard. That asymmetry means iforiginalTextis ever a React element whose first child is not a string (e.g. a ruby element when the original itself starts with kanji — same shape produced byrubyTextToReactafter this PR's change),.replacewill be invoked on a non-string and throw or silently misbehave.Extracting a small helper keeps both sides consistent and makes the fix a single point of change:
Proposed refactor
+const toComparableText = (value) => { + if (typeof value === "string") return value.replace(/\s+/g, ""); + const first = value?.props?.children?.[0]; + return typeof first === "string" ? first.replace(/\s+/g, "") : ""; +};Then in each of the three pages:
- // Convert lyrics to text for comparison - const belowOrigin = (typeof originalText === "object" ? originalText?.props?.children?.[0] : originalText)?.replace(/\s+/g, ""); - const belowTxt = - typeof text === "string" - ? text.replace(/\s+/g, "") - : typeof text?.props?.children?.[0] === "string" - ? text.props.children[0].replace(/\s+/g, "") - : ""; + // Convert lyrics to text for comparison + const belowOrigin = toComparableText(originalText); + const belowTxt = toComparableText(text);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@CustomApps/lyrics-plus/Pages.js` around lines 311 - 320, Create a small helper (e.g., extractPlainText or getTextContent) that takes a value which can be a string or a React element and returns a string with all whitespace removed (use .replace(/\s+/g, "") only when the final value is a string); then replace the repeated nested-ternaries that compute belowOrigin and belowTxt with calls to that helper and compute belowMode using showTranslatedBelow && originalText && belowOrigin !== belowTxt so all three pages use the same safe extraction logic (ensure the helper checks typeof value === "string" first, then inspects value?.props?.children?.[0] only if that child is a string).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@CustomApps/lyrics-plus/Utils.js`:
- Around line 178-186: The if statement and trailing push in the loop need to
match file formatting and avoid empty-string children: change the new guard to
use the file's style (tabs, double quotes, braced body) and add a symmetric
empty-string check before pushing the trailing segment (the result of
rubyElems[i].split("</ruby>")[1]); locate the block using symbols rubyElems,
reactChildren and react.createElement and ensure you only push the trailing part
when it's not "" so both leading and trailing empty children are prevented.
---
Nitpick comments:
In `@CustomApps/lyrics-plus/Pages.js`:
- Around line 311-320: Create a small helper (e.g., extractPlainText or
getTextContent) that takes a value which can be a string or a React element and
returns a string with all whitespace removed (use .replace(/\s+/g, "") only when
the final value is a string); then replace the repeated nested-ternaries that
compute belowOrigin and belowTxt with calls to that helper and compute belowMode
using showTranslatedBelow && originalText && belowOrigin !== belowTxt so all
three pages use the same safe extraction logic (ensure the helper checks typeof
value === "string" first, then inspects value?.props?.children?.[0] only if that
child is a string).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9e26eabc-eec7-4393-a5b5-d7faca33d662
📒 Files selected for processing (2)
CustomApps/lyrics-plus/Pages.jsCustomApps/lyrics-plus/Utils.js
fix for issue #3821
Summary by CodeRabbit