-
Notifications
You must be signed in to change notification settings - Fork 826
Charts: Reorganise shared, hooks and utils #44971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Charts: Reorganise shared, hooks and utils #44971
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 1 file.
43 files are newly checked for coverage. Only the first 5 are listed here.
|
* @param options.customArgTypes - Override default legend positioning argTypes if needed | ||
* @return Object containing story meta and story objects for legend positioning | ||
*/ | ||
export function createLegendStories< T extends Record< string, unknown > >( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't used
@@ -23,10 +23,3 @@ export const getLongestTickWidth = < T extends AnyD3Scale >( | |||
|
|||
return getStringWidth( longestTick, labelStyle ); | |||
}; | |||
|
|||
export const isSafari = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to it's own file
d4c2573
to
e8c4078
Compare
e8c4078
to
74fc7f2
Compare
271320e
to
7fd6892
Compare
36a2b06
to
bf9b891
Compare
// Utilities | ||
export { mergeThemes } from './utils/merge-themes'; | ||
|
||
// Hooks | ||
export { useDeepMemo, useGlobalChartTheme, useChartMouseHandler, useXYChartTheme } from './hooks'; | ||
|
||
// LeaderboardChart utilities | ||
export { formatMetricValue } from './components/leaderboard-chart'; | ||
|
||
// Types | ||
export type * from './types'; | ||
export type * from './visx/types'; | ||
|
||
export type { LineStyles, GridStyles, EventHandlerParams } from '@visx/xychart'; | ||
|
||
export type { RenderLineStartGlyphProps } from './components/line-chart/line-chart'; | ||
export type { LegendProps, BaseLegendProps, ChartLegendOptions } from './components/legend'; | ||
export type { ConversionFunnelChartProps, FunnelStep } from './components/conversion-funnel-chart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All exported from their respective component indexes
bf9b891
to
2f422a8
Compare
Todo:
|
1db8c86
to
4b27d18
Compare
4b27d18
to
8a2d7c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When running a build Rollup warns us about using these indexes:
(!) Export "useChartRegistration" of module "src/providers/chart-context/hooks/use-chart-registration.ts" was reexported through module "src/providers/chart-context/index.ts" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
Either change the import in "src/components/pie-chart/pie-chart.tsx" to point directly to the exporting module or do not use "output.preserveModules" to ensure these modules end up in the same chunk.
src/components/pie-chart/pie-chart.tsx
It sees them as circular dependencies, however Claude tells me this is a false positive:
Analysis
Based on my examination of the code, this is indeed a false positive warning. Here's why:
Dependency Flow Analysis
pie-chart.tsx imports useChartRegistration from src/providers/chart-context/index.ts
index.ts re-exports useChartRegistration from ./hooks/use-chart-registration
use-chart-registration.ts imports useGlobalChartsContext from ./use-global-charts-context
use-global-charts-context.ts imports GlobalChartsContext from ../global-charts-provider
Key Points:
- No actual circular dependency exists - There's a clear one-way dependency flow:
pie-chart.tsx → chart-context/index.ts → use-chart-registration.ts → use-global-charts-context.ts → global-charts-provider.tsx- No imports back to index.ts - None of the files in the chart-context directory import from the index.ts file, which would be required for a true circular dependency.
- Rollup's preserveModules configuration - The warning is triggered by Rollup's preserveModules: true setting in your config (line 38 in rollup.config.mjs). This setting creates separate chunks for each module, and Rollup gets confused when:
Module A exports something from Module B
Module C imports from Module A (getting Module B's export)
Rollup thinks this creates a circular dependency between chunks, even though the actual module dependency is linear
Why this happens:
The warning occurs because Rollup with preserveModules: true sees:
pie-chart.tsx imports from chart-context/index.ts
chart-context/index.ts re-exports from use-chart-registration.ts
Rollup puts these in different chunks and warns about potential execution order issues
However, the actual module resolution is straightforward and linear - there's no circular reference in the JavaScript module graph itself.
Conclusion:
This is a false positive. The code structure is sound and there's no actual circular dependency. This is a known limitation of Rollup when using preserveModules with re-export patterns. The warning can be safely ignored, or you could suppress it by adding a specific warning filter to your Rollup config if it becomes bothersome.
Given it is only a warning and we are exporting all the files and not a bundle I'm inclined to ignore, what do you think @kangzj? We could suppress the warning as it suggests...
I much prefer the imports using indexes, rather than separate imports from each file:
import {
useXYChartTheme,
useChartDataTransform,
useChartMargin,
useElementHeight,
} from '../../hooks';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given it is only a warning and we are exporting all the files and not a bundle I'm inclined to ignore, what do you think @kangzj? We could suppress the warning as it suggests...
I much prefer the imports using indexes, rather than separate imports from each file:
Sounds good to me! Happy to address it later as well.
8a2d7c0
to
8a67369
Compare
…structure-sharedutilshooks-directories' into charts-86-charts-restructure-sharedutilshooks-directories
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! Much cleaner and clearer 👍
Fixes CHARTS-86: Charts: restructure shared/utils/hooks directories
Proposed changes:
No functional changes, only moves:
components/shared
which has become a bit of a dumping ground. All files and folders moved to eithercomponents
,hooks
orutils
. Components by definition are shared/reusable, so they have all been moved into a flat structure.use-
test
dirglobal-chart-
toglobal-charts-
for consistencyOther information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
tests
instead oftest
, hooks not following naming conventions, etc.