fix: add fallback on chart load errors#32066
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
PR template — items to address before "Ready for review"Warnings — informational, address before merging:
See docs/readme/ready-for-review.md for the full Definition of Ready for Review. |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Why no E2E tags are needed:
The risk to existing E2E tests is negligible as the changes only affect error handling in a display component. Performance Test Selection: |
|


Description
When the TradingView charting library fails to load in the advanced token-details chart (bad CDN URL, network error, widget init failure), users previously saw a plain "Failed to load chart" message inside the WebView shell even though OHLCV data was available.
This PR adds a graceful fallback to the legacy price chart when WebView init fails before CHART_READY, and avoids flashing the advanced time-range selector during that window.
Changes:
AdvancedChart: New optional onInitFailed callback. Pre-CHART_READY ERROR messages (and native WebView errors) delegate to the parent instead of rendering AdvancedChart's error UI when onInitFailed is provided. Post-CHART_READY errors are unchanged (telemetry only; chart stays visible). Also fixes pre-ready errors arriving before onLoadEnd from leaving the skeleton stuck (removed webViewLoadedRef gate).
Price.advanced: Wires onInitFailed to fall back to PriceLegacy when OHLCV data is sufficient. Extends chartInitFailed to tri-state (null = init pending, false = ready, true = failed) so shouldFallbackToLegacy and TimeRangeSelector loading stay in sync — selector skeleton until the chart reveals or legacy fallback kicks in.
Tests: Coverage for init-failure legacy fallback, onInitFailed delegation, pre-ready error UI when no handler, and TimeRangeSelector loading behavior.
Changelog
CHANGELOG entry: Fixed token details advanced chart to fall back to the legacy price chart when the TradingView library fails to load, instead of showing a broken chart error state.
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/ASSETS-3406
Manual testing steps
Local CDN failure repro: set MM_CHARTING_LIBRARY_URL to an invalid value in .js.env, rebuild, open token details.
Screenshots/Recordings
Before
After
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
Note
Low Risk
Scoped to advanced chart error handling and token-overview fallback UX; post-ready chart behavior is unchanged and tests cover the new paths.
Overview
When the TradingView WebView fails before
CHART_READY(CDN, library boot, or native WebView error) but OHLCV data is already available, token details no longer show the advanced chart’s “Failed to load chart” state.AdvancedChartadds optionalonInitFailed. Pre-readyERRORmessages and WebView load failures call the parent instead of rendering the built-in error UI when that handler is set; post-ready errors still only notify viaonError. The oldwebViewLoadedRefgate on pre-ready errors is removed so init failures that arrive beforeonLoadEndare handled correctly.Price.advancedtracks init with tri-statechartInitFailed(nullpending,falseready,truefailed), includes init failure inshouldFallbackToLegacy, and rendersPriceLegacy.TimeRangeSelectorstays in a loading/skeleton state until the chart skeleton clears or legacy fallback applies, avoiding a flash of advanced range pills. Visibility traces recordchartInitFailedon init failure.Tests cover delegation, legacy fallback, selector loading, and unchanged error UI when
onInitFailedis omitted.Reviewed by Cursor Bugbot for commit b88eae6. Bugbot is set up for automated code reviews on this repo. Configure here.