`precomputeConflationOnInit` never uses `scheduler.postTask` — the property-rename build step mangles the host probe
Lightweight Charts™ Version: 5.2.1
Series._precomputeConflationLevels probes the browser scheduler through an inline window/self cast. The production build's ts-transformer-properties-rename (registered in tsconfig.prod.json) rewrites the property accesses in that cast, so the published bundle reads the host object under mangled names that never exist in a browser:
// dist/lightweight-charts.development.mjs
const globalObj = ((typeof window === 'object' && window) || (typeof self === 'object' && self));
if (globalObj?._internal_scheduler?._internal_postTask) {
void globalObj._internal_scheduler._internal_postTask(() => { task(); }, { _internal_priority: priority });
} else {
void Promise.resolve().then(() => task());
}scheduler, postTask and priority are host-DOM property names, not library members, but they are renamed anyway. globalObj._internal_scheduler is always undefined, so the scheduler.postTask branch is dead and the documented background scheduling never happens.
Steps/code to reproduce:
Open in Chrome ≥94 or Firefox ≥142, where window.scheduler.postTask is present. Count postTask calls during a precomputeConflationOnInit: true load:
import { createChart, CandlestickSeries } from 'lightweight-charts';
let postTaskCalls = 0;
const original = window.scheduler.postTask.bind(window.scheduler);
window.scheduler.postTask = (cb, opts) => { postTaskCalls++; return original(cb, opts); };
const chart = createChart(document.body, {
width: 600,
height: 400,
timeScale: { enableConflation: true, precomputeConflationOnInit: true, minBarSpacing: 0.001 },
});
const series = chart.addSeries(CandlestickSeries);
const base = 1600000000;
series.setData(Array.from({ length: 50000 }, (_, i) => {
const p = 100 + Math.sin(i / 50) * 10;
return { time: base + i * 86400, open: p, high: p + 1, low: p - 1, close: p + (i % 2 ? 0.5 : -0.5) };
}));
setTimeout(() => console.log('postTask calls:', postTaskCalls), 1000);Actual behavior:
Logs postTask calls: 0. Every background conflation task falls through to the Promise.resolve().then() branch and runs as a main-thread microtask before the next paint. Independently, the second argument is emitted as { _internal_priority: priority }; the Prioritized Task Scheduling spec expects the exact key priority, so the option would be ignored even if the probe matched.
Expected behavior:
The probe reads the real window.scheduler.postTask, and precompute tasks are dispatched via postTask(task, { priority }) at the configured precomputeConflationPriority. The rename step should leave host-DOM property names alone.
Suggested fix:
Keep these accesses out of the rename set — declare Scheduler.postTask and PostTaskOptions.priority as ambient globals (e.g. in src/typings/globals/index.d.ts) instead of an inline cast, or read them via bracket/string access, or exclude the three names in the transformer config. A build-artifact assertion that the emitted bundle contains scheduler.postTask (not _internal_scheduler/_internal_postTask and not _internal_priority) would prevent the regression from recurring.
Screenshots:
n/a
CodeSandbox/JSFiddle/etc link:
Repro needs a scheduler.postTask-capable browser; snippet above runs from a local bundle or the CDN build.
Source: tradingview/lightweight-charts