Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions frontend/src/ts/components/common/ChartJs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import { createEffectOn } from "../../hooks/effects";
import { useRefWithUtils } from "../../hooks/useRefWithUtils";
import { getTheme } from "../../states/theme";

function getThemeHash(): string {
return Object.values(getTheme()).join("");
}

Chart.register(chartTrendline);
type ChartJSProps<
T extends ChartType = ChartType,
Expand All @@ -38,7 +34,6 @@ export function ChartJs<T extends ChartType, TData = DefaultDataPoint<T>>(
const [canvasRef, canvasEl] = useRefWithUtils<HTMLCanvasElement>();

let chart: Chart<T, TData> | undefined;
let theme = "";

onMount(() => {
const canvas = canvasEl();
Expand All @@ -50,7 +45,6 @@ export function ChartJs<T extends ChartType, TData = DefaultDataPoint<T>>(
data: props.data,
options: addColorsToOptions(props.options as ChartOptions<T>, getTheme),
});
theme = getThemeHash();
props.onChartInit?.(chart);
});

Expand All @@ -68,15 +62,7 @@ export function ChartJs<T extends ChartType, TData = DefaultDataPoint<T>>(

const deferredData = createDeferred(() => props.data, { timeoutMs: 500 });

createEffectOn(deferredData, (data) => updateChart(data));

createEffectOn(getTheme, () => {
if (!chart) return;
const newTheme = getThemeHash();
if (theme === newTheme) return;
theme = newTheme;
updateChart(deferredData());
});
createEffectOn(deferredData, (data) => updateChart(data), { defer: true });

onCleanup(() => {
chart?.destroy();
Expand Down
1 change: 1 addition & 0 deletions packages/oxlint-config/plugin.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{
"files": ["**/*.tsx"],
"rules": {
"monkeytype-rules/no-non-reactive-access-in-components": "error",
"monkeytype-rules/prefer-arrow-in-component": "error",
"monkeytype-rules/one-component-per-file": "error",
"monkeytype-rules/component-pascal-case": "error",
Expand Down
41 changes: 41 additions & 0 deletions packages/oxlint-config/plugins/monkeytype-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,47 @@ const plugin = {
};
},
}),
"no-non-reactive-access-in-components": defineRule({
createOnce(context) {
const getComponentAncestor = (node) => {
let current = node.parent;
while (current) {
// function Foo() { return <...> }
if (
current.type === "FunctionDeclaration" &&
containsJSXReturn(current.body)
) {
return current.id?.name ?? "component";
}
// const Foo = () => { return <...> } or const Foo = function() { return <...> }
if (
(current.type === "ArrowFunctionExpression" ||
current.type === "FunctionExpression") &&
containsJSXReturn(current.body ?? current) &&
current.parent?.type === "VariableDeclarator"
) {
return current.parent.id?.name ?? "component";
}
current = current.parent;
}
return null;
};

return {
MemberExpression(node) {
if (node.object?.name === "__nonReactive") {
const componentName = getComponentAncestor(node);
if (componentName) {
context.report({
node,
message: `__nonReactive should not be accessed in component \`${componentName}\`.`,
});
}
}
},
};
},
}),
"prefer-arrow-in-component": defineRule({
meta: {
hasSuggestions: true,
Expand Down
Loading