[2.x] Fix realtime extender load order for tags & sticky (TypeError: not a constructor)#4699
Merged
Conversation
flarum/realtime registers its Realtime JS extender on the export registry at module-evaluation time, and consumers read it back via flarum.reg.get(). The combined forum.js concatenates extensions in resolveExtensionOrder() order, so realtime must be ordered before any consumer — otherwise the consumer's reg.get runs before realtime's reg.add and instantiates undefined (TypeError: mt(...) is not a constructor). Without a dependency edge that order is reverse-alphabetical by id, so consumers whose id sorts after flarum-realtime (tags, sticky) are emitted before it. flags/likes/lock/messages already declare flarum/realtime as an optional dependency; declare it on tags and sticky too (and normalise sticky's flarum-tags to flarum/tags). Fixes https://discuss.flarum.org/d/39359
a133a04 to
26c2e93
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the
flarum-tags failed to initialize / TypeError: mt(...) is not a constructorerror reported in https://discuss.flarum.org/d/39359 whenflarum/tagsandflarum/realtimeare enabled together.Root cause
flarum/realtimeregisters itsRealtimeJS extender on the export registry at module-evaluation time (flarum.reg.add('flarum-realtime', 'forum/extenders/Realtime', ...)), and consumer extensions read it back viaflarum.reg.get(...). The combinedforum.jsconcatenates extensions in the order returned byExtensionManager::resolveExtensionOrder(), so realtime must be ordered before any consumer — otherwise the consumer'sreg.getruns before realtime'sreg.addand instantiatesundefined.With no dependency edge, that order falls back to reverse-alphabetical by id (Kahn's output is reversed). Extensions whose id sorts after
flarum-realtimeare therefore emitted before it — the broken order. That'sflarum-tagsandflarum-sticky. The other realtime consumers (flags,likes,lock,messages) already declareflarum/realtimeas an optional dependency, which is why they were unaffected.Fix
Declare
flarum/realtimeas an optional dependency on the two consumers that were missing it, so realtime is always ordered ahead of them:tags— addedoptional-dependencies: ["flarum/realtime"](had none)sticky— addedflarum/realtimeto its existing list (also normalisedflarum-tags→flarum/tags)Tests
Added a regression test to
ExtensionDependencyResolutionTestproving the ordering: without the edge,[tags, realtime]resolves to the broken order; with it, realtime is placed first.