[PR #53] [MERGED] fix(google-fonts): use closure variables instead of this for plugin sstate #271

Closed
opened 2026-05-06 12:38:54 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/53
Author: @MehediH
Created: 2/25/2026
Status: Merged
Merged: 3/28/2026
Merged by: @southpolesteve

Base: mainHead: fix/google-fonts-this-binding


📝 Commits (8)

  • 1619e56 fix(google-fonts): use closure variables instead of this for plugin state
  • fe0b5f1 fix(google-fonts): fix indentation of plugin object properties inside IIFE return
  • 8f5bec9 fix: update tests to use closure-compatible plugin initialization
  • 3bf18a3 Merge branch 'origin/main' into fix/google-fonts-this-binding
  • ba6c14e fix(google-fonts): apply closure-variable fix on top of main's refactored plugin
  • a054fbb fmt
  • 46cba58 fix tests: replace plugin._isBuild direct access with initPlugin() helper
  • 41ddc05 fix: silence no-unused-vars lint warnings in font-google tests

📊 Changes

2 files changed (+414 additions, -370 deletions)

View changed files

📝 packages/vinext/src/index.ts (+225 -223)
📝 tests/font-google.test.ts (+189 -147)

📄 Description

Vite does not bind this to the plugin object when calling hooks — it extracts the hook function and calls it directly. This means this._isBuild etc. in configResolved and transform.handler refers to undefined in strict mode, crashing the dev server with:

TypeError: Cannot set properties of undefined (setting '_isBuild')

Fix: wrap the plugin in an IIFE and hold state in closure variables instead of as properties on the plugin object.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/53 **Author:** [@MehediH](https://github.com/MehediH) **Created:** 2/25/2026 **Status:** ✅ Merged **Merged:** 3/28/2026 **Merged by:** [@southpolesteve](https://github.com/southpolesteve) **Base:** `main` ← **Head:** `fix/google-fonts-this-binding` --- ### 📝 Commits (8) - [`1619e56`](https://github.com/cloudflare/vinext/commit/1619e56fd68374bdd0756aad083da86247509084) fix(google-fonts): use closure variables instead of this for plugin state - [`fe0b5f1`](https://github.com/cloudflare/vinext/commit/fe0b5f17610e3eced8434eeeeb7123dec44af45c) fix(google-fonts): fix indentation of plugin object properties inside IIFE return - [`8f5bec9`](https://github.com/cloudflare/vinext/commit/8f5bec9b6480e15e6179def26e947862b7bd8f26) fix: update tests to use closure-compatible plugin initialization - [`3bf18a3`](https://github.com/cloudflare/vinext/commit/3bf18a3217544d63c16f7e573f5c4dbe15d07b1b) Merge branch 'origin/main' into fix/google-fonts-this-binding - [`ba6c14e`](https://github.com/cloudflare/vinext/commit/ba6c14e30f2ff7e2a00e31267dcd8d557e8b90d4) fix(google-fonts): apply closure-variable fix on top of main's refactored plugin - [`a054fbb`](https://github.com/cloudflare/vinext/commit/a054fbb8625f6f99028b2391bb10c1a8e0f5b2c0) fmt - [`46cba58`](https://github.com/cloudflare/vinext/commit/46cba58466ccbafba90a41d6b11354d86c586fbc) fix tests: replace plugin._isBuild direct access with initPlugin() helper - [`41ddc05`](https://github.com/cloudflare/vinext/commit/41ddc051f1f6effbbb9c3c99dd4f9cccd8d94149) fix: silence no-unused-vars lint warnings in font-google tests ### 📊 Changes **2 files changed** (+414 additions, -370 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/index.ts` (+225 -223) 📝 `tests/font-google.test.ts` (+189 -147) </details> ### 📄 Description Vite does not bind `this` to the plugin object when calling hooks — it extracts the hook function and calls it directly. This means `this._isBuild` etc. in `configResolved` and `transform.handler` refers to `undefined` in strict mode, crashing the dev server with: ``` TypeError: Cannot set properties of undefined (setting '_isBuild') ``` Fix: wrap the plugin in an IIFE and hold state in closure variables instead of as properties on the plugin object. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:38:54 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#271
No description provided.