Skip to content

perf: wave C — interaction-gate minerals.db fetch on /tools/* widgets#46

Merged
Bissbert merged 1 commit into
mainfrom
feature/perf-wave-c
May 18, 2026
Merged

perf: wave C — interaction-gate minerals.db fetch on /tools/* widgets#46
Bissbert merged 1 commit into
mainfrom
feature/perf-wave-c

Conversation

@Bissbert
Copy link
Copy Markdown
Contributor

Summary

  • Gates the eager 8 MB minerals.db + sql-wasm.wasm download on every /tools/* route behind a hasInitiated flag that flips on first user interaction (onPointerDown on the widget root)
  • loading initial state is now false, so no spinner renders until the user actually engages — removing the visual noise on first paint
  • Target metric: /tools/measurement/ desktop total weight drops from 8,651 KiB → <500 KiB on first paint

Gating pattern

Shared hooks expose an initiate() callback; hook consumers wire it to onPointerDown on the widget root wrapper:

  • useCalculatorDatahasInitiated gate + initiate() exposed
  • useGemIdentification — same pattern
  • useGemLookup — threads initiate() from useCalculatorData

Standalone widgets set a local hasInitiated flag directly via onPointerDown on the root wrapper:

  • calculator/{DispersionCalculator,HannemanRI}
  • optical/{DichroscopeResults,PleochroismReasoner,OpticSignReasoner}
  • lab/{UvFluorescenceLookup,HeavyLiquidReference}
  • identification/HardnessReference

Hook consumers wired to initiate():

  • calculator/{SGCalculator,RICalculator,CaratEstimator}
  • identification/GemIdentifier

Test plan

  • Visit /tools/measurement/ — confirm no network request for minerals.db or sql-wasm.wasm in DevTools Network tab on page load
  • Click/tap into the SG Calculator — confirm DB fetch fires and widget populates normally
  • Repeat spot-check for /tools/optical/, /tools/lab/, /tools/identification/
  • Confirm no spinner visible on first paint of any /tools/* route
  • CI build and lint-and-check pass

Eliminates the eager 8 MB minerals.db + sql-wasm.wasm download on first
paint of every /tools/* route. Every widget that previously called
getDB() from a mount-time useEffect now gates the load behind a
hasInitiated flag that flips on first user interaction (onPointerDown
on the widget root, or a hook-exposed initiate() callback for shared
hooks).

Hooks:
- useCalculatorData: hasInitiated gate + exposed initiate()
- useGemIdentification: hasInitiated gate + exposed initiate()
- useGemLookup: threads initiate() from useCalculatorData

Standalone widgets gated locally via onPointerDown:
- calculator/{DispersionCalculator,HannemanRI}
- optical/{DichroscopeResults,PleochroismReasoner,OpticSignReasoner}
- lab/{UvFluorescenceLookup,HeavyLiquidReference}
- identification/HardnessReference

Hook consumers wired to initiate() via onPointerDown on root wrapper:
- calculator/{SGCalculator,RICalculator,CaratEstimator}
- identification/GemIdentifier

Target: /tools/measurement/ desktop total weight drops from 8,651 KiB
to <500 KiB. Widgets still feel instant on interaction; the existing
loading state handles the brief fetch window.

Part of audits/perf-2026-05/ remediation. WC1 SSG-pass-props
deliberately skipped (polish, not perf — the gate alone hits the
byte-weight acceptance target).
@github-actions
Copy link
Copy Markdown

🚀 Preview deployed to: https://42ba7aa1.gemmology-dev.pages.dev

@Bissbert Bissbert merged commit d08c823 into main May 18, 2026
5 of 6 checks passed
@Bissbert Bissbert deleted the feature/perf-wave-c branch May 18, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant