← the effing blog

Effing 0.48.0: keeping it up

We've moved canvas onto upstream @napi-rs/canvas 1.1.0, which brings CSS shadows closer to Chrome, and moved effing onto zod 4.

Effing 0.48.0 is out, and it’s a catching-up release. @effing/canvas moves onto @effing/skia 1.1.0-effing.1, our fork of upstream @napi-rs/canvas 1.1.0, and effing moves from zod 3 to zod 4. Neither adds much that’s new, but both keep us on the versions that get fixes, and a few things come out closer to Chrome along the way.

Canvas on 1.1.0

Upstream has been busy since 1.0.10, the version our fork was on. A long run of fixes makes the canvas API behave like Chrome’s, from paths and clips to gradients, filters, fonts and ImageData, and 1.1.0 adds a new text engine that draws text the same on every OS. Our fork carries the things effing relies on, such as geometricPrecision text, the encode pool, rasterizing off the JS thread, QOI and compositing groups, and those are now hooked into the new engine.

For what renderReactElement() draws, most of this changes nothing you’d see. Text is unchanged: @effing/canvas draws and measures it with the fork’s geometricPrecision text, which the new engine leaves alone. Of our 144 pixel comparisons against Chrome and satori, all but a few came out within 0.02% of before. A few improved, and two got slightly worse: a contrast(2) backdrop filter over a gradient, against Chrome, and a gradient card, against satori. Two things changed underneath:

  • Gradients are dithered, which keeps each pixel within a level of its undithered color but breaks up banding, and they’re laid out as Chrome lays them out. Gradient pixels can shift slightly.
  • blur() and contrast() filters can differ from before by a level or two, since @effing/skia now builds ctx.filter exactly as Chrome builds a canvas filter.

Shadows, the way Chrome draws them

Chrome doesn’t draw a CSS box-shadow or text-shadow the way it blurs a canvas filter: blur(). It uses a Gaussian mask blur, the same one it uses for a canvas’s shadowBlur. @effing/canvas drew its shadows with a blur() filter, which used to be close enough. With 1.1.0 building that filter exactly as Chrome’s canvas does, though, the smallest shadow blurs moved away from what Chrome shows for the same CSS.

So shadows now go through the canvas shadow API instead. @effing/canvas draws the shape far off the canvas and casts its shadow back into place, with the offset and blur mapped through the element’s transform. On our two Chrome text-shadow fixtures, the share of pixels that differ from Chrome went like this:

text-shadow0.470.48 with blur()0.48
3px 3px 2px1.68%2.48%1.49%
2px 3px 3px1.81%1.53%1.11%

Both land closer to Chrome than in 0.47. Mapping the blur through the transform also fixes box shadows on scaled elements: they’re now blurred by the element’s scale, as in Chrome, where they used to keep their unscaled blur. Against Chrome, a box shadow on a scaled, rotated or skewed element now differs in about 0.01% of pixels.

Zod 4

Effie and fn props have been validated with zod 3 until now. In 0.48.0 the whole repo is on zod 4, the starter template included, and the zod peer dependency of @effing/effie and @effing/fn is now ^4.5.0. The exported Effie schemas are zod 4 schemas, and propsSchema in an fn module is typed as a zod 4 z.ZodType. @effing/annie no longer declares a zod peer at all, since it never used one.

The range starts at 4.5.0 because earlier zod 4 releases give less detail when a value doesn’t match any branch of a union, which is how Effie describes transitions, effects, motions and backgrounds. We ran about 50 valid and invalid Effies through the old schemas on zod 3 and the new ones on several zod 4 releases. From 4.5.0 on, they accept and reject the same Effies and report issues at the same paths, apart from the differences below.

What you’ll notice is the wording of validation errors, which now follows zod 4. That shows up in the issues FFS returns for an invalid Effie:

Invalid input: expected number, received string
Unrecognized key: "extra"

Union mismatches report as before: an unrecognized key on the branch that matches is reported as such, and other mismatches as Invalid input at the union’s path. The one change is a value that partly matches several branches, such as a fade transition with both easing and through, which now gets Invalid input instead of an unrecognized-key issue.

Zod 4 also no longer lets z.number() accept Infinity, so an Effie with an infinite number is now rejected. JSON can’t express one anyway, so this only affects Effies built in code.

Also in this release

  • Invalid SVG paths draw what they can. An SVG <path>, or a path in a <clipPath>, whose d has an error partway now draws the part before the error, as browsers do, instead of failing the render.
  • clip-path: path() is checked by @effing/canvas. Path2D no longer throws on invalid path data, so @effing/canvas checks it against the SVG path grammar itself and still leaves an element with an invalid path() unclipped. An empty or whitespace-only path() is now ignored as well, as in Chrome, instead of clipping the element away.
  • z.url() in the starter. The starter template, demos and docs use z.url() instead of zod’s deprecated z.string().url().

Upgrading

Bump your @effing/* packages to 0.48.0. Things to check:

  • Upgrade zod to 4.5 or newer (see the zod 4 migration guide). Projects created from the starter before 0.48.0 are on zod 3. Your propsSchema and anything built on the Effie schemas need to be zod 4 schemas.
  • If you build Effies in code, one with an infinite number is now rejected.
  • If you match on the text of validation errors from FFS, or from parsing Effies yourself, update it to zod 4’s wording.
  • If you compare renders pixel for pixel, expect gradients, blur() and contrast() filters and shadows to shift slightly, and box shadows on scaled elements to come out with a different blur.
  • resolutions in the dev config still has to be non-empty, but its inferred type is now a plain array rather than a non-empty tuple.
  • If you draw on a canvas from createCanvas() directly, upstream 1.1.0 changes a few things. ctx.font is read as Chrome reads it, and an invalid value is ignored rather than throwing. new Path2D(d) keeps the path data that parses before an error instead of throwing. convertToBlob() takes { type }. And an alpha: false canvas starts out opaque black.

The full per-package changelogs are in the release PR.