heartwood every commit a ring

Fix dashboard crash from d3 v3 IIFE accessing this.document under ESM

85235d63 by Isaac Bythewood · 27 days ago

Fix dashboard crash from d3 v3 IIFE accessing this.document under ESM

Datamaps pulls in a nested d3 v3 whose top-level IIFE reads this.document,
which is undefined in Vite's strict ESM output. Add a small Vite transform
that rewrites it to globalThis.document in that one file.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
modified vite.config.js
@@ -1,7 +1,19 @@import { resolve } from "path";import { defineConfig } from "vite";// datamaps pulls in d3 v3, whose IIFE reads `this.document` expecting the// global object. Under ESM/strict `this` is undefined, which crashes at load.const fixD3v3GlobalThis = {  name: "fix-d3-v3-global-this",  transform(code, id) {    if (id.includes("datamaps/node_modules/d3/d3.js")) {      return code.replace("this.document", "globalThis.document");    }  },};export default defineConfig({  plugins: [fixD3v3GlobalThis],  build: {    outDir: resolve(__dirname, "analytics/static"),    emptyOutDir: true,