javascript

  • CSS Grid arrived, and the layout hacks can go

    Chrome 57 and Firefox 52 shipped it a fortnight apart in March. Replacing a grid system of nested rows, negative margins and a clearfix with fourteen lines.

  • wp_add_inline_script instead of wp_localize_script

    wp_localize_script() exists to pass translated strings to JavaScript and has been used for everything else because it was the only way to get data across. 4.5 added the…

  • webpack 3 scope hoisting, and what it actually saves

    webpack wraps every module in a function, which costs a closure per module at parse and at runtime. Scope hoisting concatenates modules that can safely share a scope…

  • React 16 error boundaries stop one component killing the page

    Before 16, an exception during render left React in an inconsistent state and the usual advice was to let it crash. 16 unmounts the whole tree by default,…

  • An async function always returns a promise

    Marking a function async changes its return value regardless of what the body does, which is obvious stated plainly and is the source of most confusion about them.…

  • The asset pipeline Laravel 5.4 shipped

    Elixir wrapped gulp, which wrapped everything else. Mix wraps webpack directly — and leaves the configuration reachable when the abstraction runs out.

  • Map keeps insertion order and takes objects as keys

    A plain object as a lookup coerces every key to a string, so 1 and “1” collide, and an object key becomes the useless string [object Object]. Map…

  • webpack resolve.alias removes the ../../..

    A deep component importing a helper writes ../../../lib/money, and the path breaks the moment the file moves — which makes reorganising a tree a mechanical exercise in fixing…

  • Getters and setters inside a class body

    A computed value usually starts as a method and becomes a property when someone forgets the parentheses. An accessor lets it be read as a property while still…

  • Source maps in production without shipping the source

    Minified stack traces are unreadable, and the usual fix — shipping source maps — publishes the original source to anyone who opens devtools. Both problems have the same…