javascript

  • wp_enqueue_script in the editor is a different hook

    Scripts for the editing screen do not go on admin_enqueue_scripts — there is a dedicated hook, and using the wrong one loads the editor bundle on every admin…

  • React 16 rewrote how a component fails

    An error in one component used to blank the page. 16 unmounts the whole tree deliberately — and gives you the mechanism to stop it.

  • Object spread in ES2018, and Object.assign’s retirement

    Merging objects meant Object.assign({}, a, b), and forgetting the empty first argument mutated a — a bug that shows up two components away from where it was written.…

  • A 500 from fetch is a resolved promise, not a rejected one

    A promise from fetch resolves for any response the server returned, including a 500, and rejects only when the request could not be made at all. This is…

  • Declaring a type for a library that has none

    A JavaScript dependency without types is either an any, which defeats the point, or a declaration file, which takes ten minutes and only needs to describe what you…

  • The passive event listener flag, and the scroll jank it fixes

    A touchstart or wheel listener may call preventDefault, so the browser cannot start scrolling until the handler has run — which means every such listener delays scroll by…

  • splitChunks defaults are usually right

    CommonsChunkPlugin required declaring which modules were common, which meant knowing the dependency graph in advance and updating the configuration whenever it changed. chunks: ‘all’ lets it split synchronous…

  • Debounce without a library

  • IntersectionObserver replaces a scroll handler

    Lazy-loading images with a scroll listener means running getBoundingClientRect for every candidate on every scroll event, which forces layout and is exactly the work that makes scrolling stutter.…

  • AbortController cancels a fetch, finally

    A type-ahead search fires a request per keystroke, and the responses arrive out of order — so the results for “lap” can overwrite the results for “laptop”. Aborting…