v0.4.1: drop renderChatMessage, register renderChatMessageHTML

Foundry v13 deprecated renderChatMessage in favor of
renderChatMessageHTML (which passes an HTMLElement, not a jQuery
wrapper). Subscribing to the deprecated hook re-emits Foundry's
compatibility warning on every chat render in worlds still running
v13.351 (the foundry-hooks-lib module's tests run against such a
world).

v0.3.0 already narrowed scope to Foundry v14 only (HOOK_CONTRACT.md
section 9), but the registered hook set still included
renderChatMessage as a legacy fallback. There is no Foundry v14
hook by that name, so the entry was dead weight — and worse, any
v13.351 world running the v14-only library would still see the
deprecation warning every chat render.

Changes:
- registered-hooks.js: replace renderChatMessage entry with
  renderChatMessageHTML. Update arg shape (HTML passes HTMLElement,
  not jQuery). Add comment explaining the deprecation.
- README.md / HOOK_CONTRACT.md section 6: list renderChatMessageHTML
  instead of renderChatMessage.
- tests/verify-hooks-lib.mjs: update stub arg shape from
  [{id}, {}, {}] to [{id}, {}] (v14 signature).

Verification:
- node tests/verify-hooks-lib.mjs: 546/546 (unchanged)
- node tests/perf.mjs: 6/6, median 0.0003ms/fire (well under
  the 0.1ms budget in HOOK_CONTRACT.md section 7)
- node --check on all scripts + tests: clean

Push: Gitea only.

Note: battle-focus's own main.js line 144 still has a
Hooks.on('renderChatMessage', ...) listener for its 'Open in
Journal' button wiring. That listener fires the deprecation warning
on the user's console. Fixing it is a battle-focus change, out of
scope for this turn (hooks-lib only).
This commit is contained in:
2026-06-20 22:49:32 -04:00
parent 59a3f7bc0c
commit 2fabb5e98f
4 changed files with 11 additions and 4 deletions

View File

@@ -131,7 +131,7 @@ Lifecycle, document CRUD (Actor/Token/Item/Scene/JournalEntry/
ActiveEffect/Combat/Combatant), combat lifecycle, chat & rolls (incl.
dnd5e v2 roll hooks), canvas/scene/UI (canvasInit/Ready/Pan, controlToken,
hoverToken, targetToken, lighting/sightRefresh, collapseSidebar,
changeSidebarTab, getSceneControlButtons, renderChatMessage,
changeSidebarTab, getSceneControlButtons, renderChatMessageHTML,
renderChatInput, renderJournalPageSheet, rtcSettingsChanged), and more.
Full list: `scripts/internal/registered-hooks.js`.

View File

@@ -299,7 +299,7 @@ hooks. Each registration uses the wrapper from §2 to produce envelopes.
- `lightingRefresh`, `sightRefresh`
- `collapseSidebar`, `changeSidebarTab`, `getSceneControlButtons`
- `collapseSceneNavigation`
- `renderChatMessage`, `renderChatInput`, `renderJournalPageSheet`
- `renderChatMessageHTML`, `renderChatInput`, `renderJournalPageSheet`
- `initializePointSourceShaders`
- `rtcSettingsChanged`

View File

@@ -93,8 +93,15 @@ export const HOOK_REGISTRY = [
{ envelope: "combatInactive", mode: "sync", raw: ["updateCombat"], synthesized: true },
// --- Chat & rolls ---
// Note: renderChatMessage (the v13 jQuery-wrapper hook) is
// intentionally NOT registered. Foundry v13 deprecated it in favor
// of renderChatMessageHTML (HTMLElement). Consumers wanting chat
// message rendering events should subscribe to renderChatMessageHTML
// (or renderJournalPageSheet for journal pages). Subscribing to the
// deprecated hook here would re-emit Foundry's compatibility warning
// on every chat render in worlds still running v13.351.
{ envelope: "createChatMessage", mode: "async", raw: ["createChatMessage"] },
{ envelope: "renderChatMessage", mode: "sync", raw: ["renderChatMessage"] },
{ envelope: "renderChatMessageHTML", mode: "sync", raw: ["renderChatMessageHTML"] },
{ envelope: "renderChatInput", mode: "sync", raw: ["renderChatInput"] },
{ envelope: "dnd5e.rollAttackV2", mode: "async", raw: ["dnd5e.rollAttackV2"] },
{ envelope: "dnd5e.rollDamageV2", mode: "async", raw: ["dnd5e.rollDamageV2"] },

View File

@@ -516,7 +516,7 @@ function syntheticArgsFor(rawName) {
if (rawName === "collapseSidebar" || rawName === "collapseSceneNavigation") return [{}, true];
if (rawName === "changeSidebarTab") return [{}];
if (rawName === "getSceneControlButtons") return [[]];
if (rawName === "renderChatMessage") return [{ id: "m1" }, {}, {}];
if (rawName === "renderChatMessageHTML") return [{ id: "m1" }, {}];
if (rawName === "renderChatInput") return [{}, {}, {}];
if (rawName === "renderJournalPageSheet") return [{}, {}, {}];
if (rawName === "initializePointSourceShaders") return [{}];