fix: add null/undefined guards for array access and navigation

- MasteryDisplay.svelte: Use optional chaining for split()[0] array access
  - formatRingStat().split('+')[0] -> split('+')[0]?.trim() ?? ''
  - formatEarringStat().split('+')[0] -> split('+')[0]?.trim() ?? ''
- TeamView.svelte: Same fix for formatAxSkill().split('+')[0]
- +layout.svelte: Add null guards for 'to' parameter and 'mainContent' in callback
  - Check !to before accessing to.url
  - Re-check !mainContent inside requestAnimationFrame callback

Fixes "Object is possibly 'undefined'" and "is possibly 'null'" errors with
noUncheckedIndexedAccess: true and strict null checks.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Justin Edmund 2025-11-28 18:15:09 -08:00
parent de73c1937e
commit bbaa5bf221
3 changed files with 7 additions and 6 deletions

View file

@ -88,7 +88,7 @@
<ModificationSection title="AX Skills" visible={true}>
{#each weapon.ax as axSkill}
<StatModifierItem
label={formatAxSkill(axSkill).split('+')[0].trim()}
label={formatAxSkill(axSkill).split('+')[0]?.trim() ?? ''}
value={`+${axSkill.strength}`}
suffix={axSkill.modifier <= 2 ? '' : '%'}
variant="enhanced"

View file

@ -46,7 +46,7 @@
{#if iconUrl}
<img
src={iconUrl}
alt={formatRingStat(ring.modifier, ring.strength, locale).split('+')[0].trim()}
alt={formatRingStat(ring.modifier, ring.strength, locale).split('+')[0]?.trim() ?? ''}
class="mastery-icon"
/>
{/if}
@ -54,7 +54,7 @@
<span class="mastery-content">
{#if variant === 'detailed'}
<strong class="mastery-label">
{formatRingStat(ring.modifier, ring.strength, locale).split('+')[0].trim()}
{formatRingStat(ring.modifier, ring.strength, locale).split('+')[0]?.trim() ?? ''}
</strong>
<span class="mastery-value">
+{ring.strength}{getRingStat(ring.modifier)?.suffix || ''}
@ -81,7 +81,7 @@
{#if iconUrl}
<img
src={iconUrl}
alt={formatEarringStat(earring.modifier, earring.strength, locale, characterElement).split('+')[0].trim()}
alt={formatEarringStat(earring.modifier, earring.strength, locale, characterElement).split('+')[0]?.trim() ?? ''}
class="mastery-icon"
/>
{/if}
@ -89,7 +89,7 @@
<span class="mastery-content">
{#if variant === 'detailed'}
<strong class="mastery-label">
{formatEarringStat(earring.modifier, earring.strength, locale, characterElement).split('+')[0].trim()}
{formatEarringStat(earring.modifier, earring.strength, locale, characterElement).split('+')[0]?.trim() ?? ''}
</strong>
<span class="mastery-value enhanced">
+{earring.strength}{getElementalizedEarringStat(earring.modifier, characterElement, locale)?.suffix || ''}

View file

@ -58,10 +58,11 @@
// Handle scroll restoration or reset after navigation
afterNavigate(({ from, to, type }) => {
if (!mainContent) return;
if (!mainContent || !to) return;
// Use requestAnimationFrame to ensure DOM has updated
requestAnimationFrame(() => {
if (!mainContent) return;
const key = to.url.pathname + to.url.search;
// Only restore scroll for browser back/forward navigation