High "Unused JavaScript" warnings in Fusion generated bundles (default.js) - Best practices for Code Splitting? #72
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Hello 👋 @Gapuccino, Let me go through your questions briefly: 1. Code splitting in custom blocksYes, it’s safe and recommended to use code splitting, but the preferred way in Arc is to use the engine’s built-in lazy loading rather than custom Webpack tweaks. For any heavy feature/block, you can mark it as lazy so it’s built as a separate chunk and only loaded when needed, for example: const Feature = () => {
return <HeavyThing />;
};
Feature.lazy = ['default']; // or true for all outputs
export default Feature;This works nicely with server-side rendering and is the officially supported pattern. 2. Webpack / configurationYou generally don’t need to override Webpack. Tree-shaking is already enabled; the bigger wins come from how you import things:
3. Heavy third-party librariesFor large libs (video players, charts, date libs, etc.), a few patterns help:
4. What you can realistically improve
If you’d like to share one concrete example (e.g., which video or chart library you’re using), I can help sketch a more specific pattern for that use case. More information about Code-splitting your can see in the following docs: Best, Rado |
Beta Was this translation helpful? Give feedback.
-
|
Hey @Gapuccino I'm adding the Lazy-load Feature BlockThis folder demonstrates how to build a Fusion block that keeps its initial Key pieces
How it works
This pattern keeps the customer-facing experience responsive on slower devices // components/features/lazy-load/chart-renderer.jsx
import React from 'react';
import { Line } from 'react-chartjs-2';
const labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'];
const datasetValues = [120, 150, 180, 160, 210];
// Static dataset keeps the renderer focused on wiring up Chart.js.
const data = {
labels,
datasets: [
{
label: 'Page views',
data: datasetValues,
lineTension: 0.3,
borderColor: '#1890ff',
backgroundColor: 'rgba(24, 144, 255, 0.1)',
borderWidth: 2,
pointRadius: 3,
},
],
};
const options = {
responsive: true,
maintainAspectRatio: false,
legend: { display: false },
scales: {
yAxes: [
{
ticks: { beginAtZero: true },
gridLines: { color: 'rgba(15, 23, 42, 0.1)' },
},
],
},
};
// Rendered only once the lazy chunk finishes downloading.
const ChartRenderer = () => (
<div className="c-chart-block__chart-container">
<Line data={data} options={options} />
</div>
);
export default ChartRenderer;// components/features/lazy-load/default.jsx
import React, { Suspense, lazy } from 'react';
// Load the heavy chart bundle on demand so the block shell stays lightweight.
const LazyChartRenderer = lazy(() =>
import(
/* webpackChunkName: "chart-block-chart-renderer" */
'./chart-renderer'
),
);
const ChartBlock = () => (
<div className="c-chart-block">
<div className="c-chart-block__summary">
<p className="c-chart-block__label">Page views</p>
<p className="c-chart-block__value">210</p>
<p className="c-chart-block__change" aria-label="Change since Monday: +90">
▲ +90
</p>
</div>
<Suspense
fallback={
<div className="c-chart-block__chart-container c-chart-block__placeholder">
Loading chart…
</div>
}
>
{/* The renderer pulls in Chart.js only when users scroll this far. */}
<LazyChartRenderer />
</Suspense>
</div>
);
ChartBlock.label = 'Chart Block';
ChartBlock.icon = 'chart';
ChartBlock.lazy = ['default'];
export default ChartBlock;Here is how fusion renders the block enclosed in <div data-fusion-lazy-id="f0fmcdKYFKb816e">
<div class="c-chart-block">
<div class="c-chart-block__summary">
<p class="c-chart-block__label">Page views</p>
<p class="c-chart-block__value">210</p>
<p class="c-chart-block__change" aria-label="Change since Monday: +90">▲ +90</p>
</div>
<!--$-->
<div class="c-chart-block__chart-container">
<canvas height="150" width="300">
</canvas>
</div>
<!--/$-->
</div>
</div>
<div class="c-chart-block__chart-container">
<canvas height="150" width="300">
</canvas>
</div>
</div>This is the chart rendered:
Hope this helps! |
Beta Was this translation helpful? Give feedback.


Hello 👋 @Gapuccino,
You’re right that
combinations/default.jsis usually what Lighthouse flags for “Reduce unused JavaScript”, andengine/react.jsis part of the Arc runtime, so you have limited control over that one.Let me go through your questions briefly:
1. Code splitting in custom blocks
Yes, it’s safe and recommended to use code splitting, but the preferred way in Arc is to use the engine’s built-in lazy loading rather than custom Webpack tweaks.
For any heavy feature/block, you can mark it as lazy so it’s built as a separate chunk and only loaded when needed, for example: