Skip to content

Commit 95749ed

Browse files
committed
fix: keep the pure annotations of forwardRef calls
swc added them to the build, Vite does not: without them a bundler keeps Chart and its Chart.js core even when only an event helper is imported. The annotations are in the sources now, and size-limit measures a helper-only import. The type test of plugins on the generic Chart, lost in the move from tsd, is back.
1 parent b93ce4d commit 95749ed

4 files changed

Lines changed: 23 additions & 4 deletions

File tree

‎.size-limit.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@
1616
"path": "dist/index.js",
1717
"import": "{ Line }",
1818
"limit": "600 B"
19+
},
20+
{
21+
"name": "Event helper",
22+
"path": "dist/index.js",
23+
"import": "{ getElementAtEvent }",
24+
"limit": "100 B"
1925
}
2026
]

‎src/chart.spec.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,14 @@ describe('Chart', () => {
440440
expect(element.props.plugins).toEqual([]);
441441
});
442442

443+
it('should accept plugins typed for another chart type', () => {
444+
const element = (
445+
<Chart type='scatter' data={data} plugins={[] as Plugin<'bar'>[]} />
446+
);
447+
448+
expect(element.props.plugins).toEqual([]);
449+
});
450+
443451
it('should accept datasets of different chart types', () => {
444452
const multiTypeData = {
445453
datasets: [

‎src/chart.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,6 @@ function ChartComponent<
112112
);
113113
}
114114

115-
export const Chart = forwardRef(ChartComponent) as BaseChartComponent;
115+
export const Chart = /* @__PURE__ */ forwardRef(
116+
ChartComponent
117+
) as BaseChartComponent;

‎src/typedCharts.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ function createTypedChart<T extends ChartType>(
2525
) {
2626
ChartJS.register(registerables);
2727

28-
return forwardRef<ChartJSOrUndefined<T>, Omit<ChartProps<T>, 'type'>>(
29-
(props, ref) => <Chart {...props} ref={ref} type={type} />
30-
) as TypedChartComponent<T>;
28+
return /* @__PURE__ */ forwardRef<
29+
ChartJSOrUndefined<T>,
30+
Omit<ChartProps<T>, 'type'>
31+
>((props, ref) => (
32+
<Chart {...props} ref={ref} type={type} />
33+
)) as TypedChartComponent<T>;
3134
}
3235

3336
export const Line = /* #__PURE__ */ createTypedChart('line', LineController);

0 commit comments

Comments
 (0)