Google Charts collision behaviour causes issues in Storybook/SPA contexts
- Dominant language
- JavaScript
- Stars
- 1.4k
- Forks
- 383
- Avg merge
- 4d 14h
- Merged PRs (30d)
- 77
Description
## Bug Description
For those with access to the 10up Slack, this link will provide some context: https://10up.slack.com/archives/CBKKQEBR9/p1678392621467249
Essentially, the fix for the Google Charts instability we saw, largely around other WordPress plugins also loading Google Charts (of a different version), presents its own issues. Mostly that the new Charts check for charts already being loaded and will de-initialise Google Charts if it _is_ loaded on the Site Kit Dashboard context. See this PR: #6461
This means that Storybook, being a Single Page App, will crash Google Charts after navigating around 1-2 times. See:

Removing this line will fix the issue: https://github.com/google/site-kit-wp/blob/2b74402c0c91af37062b446c8adad3d88f2aaaf3/assets/js/components/GoogleChart/index.js#L144
Right now this affects Storybook and no code in production, but this could severely hamper the feasibility of #6650.
Short-term, for testing, we might want to disable the above line when in a Storybook context, but long-term we will likely need a better fix for the underlying issue with Google Charts.
## Steps to reproduce
1. Go to https://google.github.io/site-kit-wp/storybook/develop/?path=/story/modules-searchconsole-widgets-searchfunnelwidget--search-console-zero-state
2. Click the "Ready" story in `SearchFunnelWidget`
3. Click "Ready with Activate Analytics CTA"
4. Click "Ready with Analytics not active"
5. See Google Charts in an error state. It continues to be in an error state until the page is refreshed.
---------------
_Do not alter or remove anything below. The following sections will be managed by moderators only._
## Acceptance criteria
* In Storybook, the charts keep rendering as the user navigates from one chart story to the next. No chart shows an error state or disappears.
* The existing Google Charts behavior is unchanged:
* On the Site Kit dashboard, the charts keep rendering as the user navigates without reloading the page.
* On a Site Kit screen, the charts still render when another plugin has already loaded a different version of Google Charts.
* On the WordPress dashboard, the Site Kit "Unique Visitors" chart renders nothing, rather than a broken chart, when another plugin has already loaded Google Charts.
## Implementation Brief
*
### Test Coverage
*
## QA Brief
*
## Changelog entry
*
Contributor guide
Research direction
Start with assets/js/components/GoogleChart/index.js, especially the Google Charts check at the line referenced in the issue, and review PR #6461 for the existing behavior. Reproduce the failure by navigating through the listed Storybook stories, then verify that charts continue rendering in Storybook while preserving the dashboard and WordPress behavior described in the acceptance criteria.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100