proomt

Search

Search posts, papers, and topics

All posts

WebKitKai Tamkun7 min readintermediate

Fixing Top-Level Await in Safari

Summary

Safari’s module loader was rewritten in C++ to follow the ECMAScript spec, fixing ordering and uninitialized‑export bugs that broke top‑level await. The new loader passes test262, WPT, and a custom fuzzer, and restores reliable module loading performance.

  • Old loader was a self‑hosted JavaScript builtin based on a dead WHATWG proposal; it couldn’t correctly handle async module execution.
  • Bug manifested as out‑of‑order dynamic imports and "Cannot access … before initialization" errors when using top‑level await.
  • Rewrite replaced the JS builtin with native C++ code, implementing spec algorithms directly and using a flow‑graph to order implementation.
  • Testing leveraged Bun’s real‑world cases, a generated module‑graph fuzzer, and full test262/WPT suites to verify correctness and performance.

Top‑level await is now part of the JavaScript spec and widely used for async initialization (e.g., loading config, auth, or WASM). Reliable support in Safari removes a long‑standing compatibility gap, letting developers use the same module patterns across all browsers without work‑arounds.

8/10

Related reading

  1. Release Notes for Safari Technology Preview 250

    Safari Technology Preview 250 ships a batch of web‑platform updates, including new JavaScript resource‑management syntax, several CSS properties, streaming fetch bodies, and WebAssembly SIMD extensions. It also fixes a range of accessibility, rendering, and networking bugs.

    WebKitwebkit.org3 minrelease
  2. Release Notes for Safari Technology Preview 252

    Safari Technology Preview 252 adds several WebKit platform updates, including new CSS features like named-feature() in @supports and unprefixed user-select, plus bug fixes across accessibility, animations, HTML, and JavaScript. The release also corrects worker termination, Promise.try behavior, and line‑clamp rendering, which can affect Safari‑targeted web apps.

    WebKitwebkit.org10 minrelease
  3. Release Notes for Safari Technology Preview 251

    Safari Technology Preview 251 introduces new CSS features like `@supports at-rule()` and `object-view-box`, alongside new JavaScript capabilities including `Iterator.prototype.includes()` and WebAssembly Memory64. This release also includes numerous bug fixes across HTML, CSS, and Canvas, and deprecates several non-standard CSS properties.

    WebKitwebkit.org19 minrelease
  4. Fixing Server Component Bundle Leaks in Next.js with AST Linting

    Server‑only code can silently inflate client bundles in Next.js 15+ apps. The article shows how to spot leaks with @next/bundle-analyzer, prevent them by removing shared barrel files or adding the `server-only` guard, and enforce a deny‑list of server modules via a custom ESLint rule that scans the AST of files with a `'use client'` directive. The rule is wired into a CI bundle‑budget check using…

    SitePointsitepoint.com14 min
  5. WebKit Features for Safari 27.0

    Safari 27.0 adds a local MCP server for AI‑driven automation, a fully stylable `<select>` via `appearance: base-select` and new pseudo‑elements, the `<model>` element for embedding 3D assets, `sizes="auto"` for responsive images, a `shadowrootslotassignment` attribute for declarative shadow roots, and a large set of quality‑focused fixes (844 resolved issues).

    WebKitwebkit.org84 min
  6. Eliminating AI Code Hallucinations with TypeScript Compiler Diagnostics and TDD Loops

    The article shows how to replace raw TypeScript compiler output with a programmatic JSON feedback loop that merges diagnostics and Vitest test failures, feeding the structured data back to an LLM coding agent for self‑correction. It provides concrete code for extracting, enriching, validating, and de‑duplicating errors, and demonstrates token savings and deterministic iteration until compilation…

    SitePointsitepoint.com15 min