I seem to have a problem using hooks.
In this Tips and Tricks thread, Tones asked
I thought I’d give it a try. I have no idea how to do this in wikitext, but I thought I might be able to at least contribute a JavaScript solution. And hooks sound perfect for this, as there is a th-renaming-tiddler hook that presumably matches. But clearly I misunderstand something, because the code in the handler is not called.
Can someone tell me what’s wrong with this?:
/*\
title: $:/_/my/core/modules/startup/rename.js
type: application/javascript
module-type: startup
Add hook for renames.
\*/
"use strict";
// Export name and synchronous status
exports.name = "rename";
exports.platforms = ["browser"];
exports.after = ["startup"];
exports.synchronous = true;
console.log("AAA: Renaming listener: running in global context");
exports.startup = function() {
console.log("BBB: Renaming listener: running in `startup` context");
$tw.hooks.addHook("th-renaming-tiddler", function (newTid, oldTid) {
console.log("CCC: Renaming listener: running inside hook");
console.log('Renaming', newTid, oldTid)
return newTid
});
};
The lines AAA and BBB are hit during startup. But when I open a tiddler, change its name and save it, I would expect CCC to be hit. It’s not.
Am I misunderstanding what th-renaming-tiddler is supposed to do? Am I somehow misusing it? Might I be adding the hook too early? Or too late?
Any suggestions?

