[2.x] fix(flags): drop literal 'undefined' from Inappropriate reason and lazy-load FlagPostModal#4659
Merged
Merged
Conversation
…and lazy-load FlagPostModal
Two related changes to the Inappropriate flag-post path:
1. When no Community Guidelines URL is configured, the reason text
rendered the literal token "{undefined}" — the translator
stringifies undefined values passed into a rich placeholder. Use
a separate translation key with no link placeholder when the URL
is unset, instead of trying to pass `undefined` as the `<a>` slot.
2. The flag modal was imported eagerly via a side-effect import in
forum.ts and a static import in addFlagControl.js, so its ~4 KB
was always shipped in the main forum bundle even for users who
never report a post. Switch to the documented lazy-load pattern
(`app.modal.show(() => import('./components/FlagPostModal'), ...)`)
and declare the chunk directory via `Extend\Frontend::jsDirectory`
so the chunked sub-bundle is published.
Closes #4574
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.
Summary
Two related changes to the Flarum-Flags "Inappropriate" flag-post path:
Fix
{undefined}rendering when no Community Guidelines URL is set. With no URL configured, the modal currently renders:The reason:
FlagPostModalpassesundefinedas the<a>rich-placeholder value to the translator, which stringifies it (the translator wraps undefined args as'{undefined}'at Translator.tsx:131, and<a>is not in the auto-provided element fallback list).Use a separate translation key (
reason_inappropriate_text_no_guidelines) when the URL is unset, instead of trying to passundefinedas a placeholder. Matches the reporter's suggested wording ("This post is offensive or abusive.").Lazy-load
FlagPostModal. The modal was imported eagerly via a side-effectimport './components/FlagPostModal'inforum.tsplus a staticimport FlagPostModal from ...inaddFlagControl.js, so its ~4 KB was always shipped in the main forum bundle even for users who never click flag. Switch to the documented lazy-load pattern:forum.jsdrops from 12,454 → 11,509 bytes;FlagPostModal.jsbecomes a deferred ~4 KB chunk loaded on first click.Required follow-up: declare
->jsDirectory(__DIR__.'/js/dist/forum')on theExtend\Frontend('forum')registration so Flarum's asset publisher copies the chunked sub-bundles intoassets/extensions/flarum-flags/forum/components/. Without this, the chunk requests 404.Backwards compatibility (lazy-load)
FlagPostModalis no longer in the registry at boot time — it's only registered when the lazy chunk loads (first flag-button click). Third-party extensions using the string-path form ofextend()(extend('flarum/flags/components/FlagPostModal', 'view', fn)) are unaffected: the registry'sonLoadhook applies pending patches when the chunk lands (common/extend.ts:36-43).Extensions using the direct-prototype form (
import FlagPostModal from 'flarum/flags/...'; extend(FlagPostModal.prototype, ...)) at initializer-time would break, because the import would resolve toundefineduntil the chunk loads. The string-path form is the documented recommended pattern for cross-extension extension specifically because of this; any extension targeting 2.x's registry-based module model should already be using it.Test plan
{undefined}).FlagPostModal*.jsrequest in Network tab.assets/extensions/flarum-flags/forum/components/FlagPostModal.js; modal renders.Closes #4574