Rules Hub

Coding Rules Library

← Back to all rules
frontend ruleStack: general
clean-codemodern-jsabort-controllerapi-standards

Assume universal support for AbortController

Avoid defensive feature detection for AbortController as it is supported in all modern browsers and Node.js.

PR: Feat/FCK-1623 - Adding eAvis widget to the sidebar #3643Created: Dec 8, 2025

Bad example

Old codets
1useEffect(() => {
2 let controller: AbortController | undefined;
3
4 // Unnecessary feature detection for a standard API
5 if ('AbortController' in window) {
6 controller = new AbortController();
7 }
8
9 const signal = controller?.signal;
10
11 fetch('/api/data', { signal });
12}, []);

Explanation (EN)

Defensively checking for 'AbortController' is outdated and adds unnecessary noise. All modern browsers and active Node.js versions support it natively.

Objašnjenje (HR)

Defenzivna provjera za 'AbortController' je zastarjela i dodaje nepotreban šum. Svi moderni preglednici i aktivne verzije Node.js-a ga podržavaju nativno.

Good example

New codets
1useEffect(() => {
2 // Instantiate directly; no checks needed
3 const controller = new AbortController();
4 const { signal } = controller;
5
6 fetch('/api/data', { signal });
7
8 return () => controller.abort();
9}, []);

Explanation (EN)

Instantiate AbortController directly. This simplifies the code, removes undefined checks, and relies on modern standard compliance.

Objašnjenje (HR)

Instanciraj AbortController izravno. To pojednostavljuje kod, uklanja provjere za undefined i oslanja se na moderne standarde.