Skip to content

Centralize neowiki.registration fire on ext.neowiki module load#804

Merged
JeroenDeDauw merged 3 commits intomasterfrom
centralize-registration-hook-fire
May 1, 2026
Merged

Centralize neowiki.registration fire on ext.neowiki module load#804
JeroenDeDauw merged 3 commits intomasterfrom
centralize-registration-hook-fire

Conversation

@malberts
Copy link
Copy Markdown
Collaborator

@malberts malberts commented Apr 30, 2026

Result of extensive back and forth with @malberts.
Context: the NeoWiki codebase, PR #803 (the just-merged targeted fix), and the project's mw.hook replay-on-late-subscribe semantics covered by HookRegistration.spec.ts.
Written by Claude Code, Opus 4.7

Follows-up to #803

Related to #686

The previous setup duplicated mw.hook( 'neowiki.registration' ).fire() in each of the six mount-point initializers in neowiki.ts, plus a seventh in RedHerb's SubjectFinder init added by PR #803. Each fire constructed a fresh FrontendRegistrar over the same singleton registries — pure boilerplate that any new custom mount point would have to remember to replicate or risk extension property types silently failing to register.

Extract a single fireRegistrationHook() and call it once at ext.neowiki module load, before the initializers. Subscribers that load before or after benefit equally thanks to mw.hook's documented replay-on-late-subscribe behavior, already covered by HookRegistration.spec.ts. The seven redundant per-mount fires are removed.

A new boot-time test asserts that loading @/neowiki fires the hook with a registrar wired to the live NeoWikiExtension registries — registering a fake type via the fired registrar must be observable on the singleton's PropertyTypeRegistry and TypeSpecificComponentRegistry. This catches a missing fire, a fully detached registrar, and a half-detached registrar (where one registry is fresh and the other live — would only surface as broken Vue rendering in the browser).

@malberts malberts force-pushed the centralize-registration-hook-fire branch 3 times, most recently from 1ae224f to a9b4a3b Compare April 30, 2026 15:57
malberts and others added 2 commits April 30, 2026 19:50
Follows-up to #803

The previous setup duplicated `mw.hook( 'neowiki.registration' ).fire()`
in each of the six mount-point initializers in `neowiki.ts`, plus a
seventh in RedHerb's SubjectFinder init added by PR #803. Each fire
constructed a fresh `FrontendRegistrar` over the same singleton
registries — pure boilerplate that any new custom mount point would
have to remember to replicate or risk extension property types silently
failing to register.

Extract a single `registerExtensions()` (mirroring the PHP
`NeoWikiExtension::ensureExtensionsRegistered()`) and call it once at
`ext.neowiki` module load, before the initializers. Subscribers that
load before or after benefit equally thanks to `mw.hook`'s documented
replay-on-late-subscribe behavior, already covered by
`HookRegistration.spec.ts`. The seven redundant per-mount fires are
removed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Boot is now the single point of truth for `neowiki.registration`. A
regression that drops or misplaces the module-load fire would silently
break every subscriber and only surface in the browser. Pin the
contract with a unit test: with `neoWikiTestMode = false`, importing
`@/neowiki` must fire the hook with a registrar wired to the live
`NeoWikiExtension` registries — registering a fake type via the fired
registrar must be observable on the singleton's `PropertyTypeRegistry`
*and* `TypeSpecificComponentRegistry`. This catches a missing fire, a
fully detached registrar, and a half-detached registrar (where one
registry is fresh and the other live — would only surface as broken
Vue rendering in the browser).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@malberts malberts force-pushed the centralize-registration-hook-fire branch from a9b4a3b to 8f82a3b Compare April 30, 2026 17:51
@malberts malberts marked this pull request as ready for review April 30, 2026 18:05
Comment thread resources/ext.neowiki/src/neowiki.ts Outdated
( window as unknown as { neoWikiTestMode?: boolean } ).neoWikiTestMode === true;

if ( !isTestEnvironment ) {
registerExtensions();
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered matching the PHP ensureExtensionsRegistered(), but the TS does not have a guard, and this is the point where extensions get registered.


function registerExtensions(): void {
const ext = NeoWikiExtension.getInstance();
mw.hook( 'neowiki.registration' ).fire(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regsiterExtensions? that seems not quite right. It fires a hook which extensions often register handlers for. So triggerRegistrationHooks, fireRegistrationEvent, or similar, seems better

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went back to the original name that literally matches what happens: fireRegistrationHook.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@JeroenDeDauw JeroenDeDauw merged commit adaa160 into master May 1, 2026
9 checks passed
@JeroenDeDauw JeroenDeDauw deleted the centralize-registration-hook-fire branch May 1, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants