Skip to content

Commit a63c53c

Browse files
committed
[2.x] fix(flags): drop literal 'undefined' from Inappropriate reason 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
1 parent d03ba16 commit a63c53c

5 files changed

Lines changed: 8 additions & 7 deletions

File tree

extensions/flags/extend.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
return [
3030
(new Extend\Frontend('forum'))
3131
->js(__DIR__.'/js/dist/forum.js')
32+
->jsDirectory(__DIR__.'/js/dist/forum')
3233
->css(__DIR__.'/less/forum.less')
3334
->route('/flags', 'flags', AssertRegistered::class),
3435

extensions/flags/js/src/forum/addFlagControl.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ import app from 'flarum/forum/app';
33
import PostControls from 'flarum/forum/utils/PostControls';
44
import Button from 'flarum/common/components/Button';
55

6-
import FlagPostModal from './components/FlagPostModal';
7-
86
export default function () {
97
extend(PostControls, 'userControls', function (items, post) {
108
if (post.isHidden() || post.contentType() !== 'comment' || !post.canFlag()) return;
119

1210
items.add(
1311
'flag',
14-
<Button icon="fas fa-flag" onclick={() => app.modal.show(FlagPostModal, { post })}>
12+
<Button icon="fas fa-flag" onclick={() => app.modal.show(() => import('./components/FlagPostModal'), { post })}>
1513
{app.translator.trans('flarum-flags.forum.post_controls.flag_button')}
1614
</Button>
1715
);

extensions/flags/js/src/forum/components/FlagPostModal.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ export default class FlagPostModal extends FormModal {
9292
onclick={withAttr('value', this.reason)}
9393
/>
9494
<strong>{app.translator.trans('flarum-flags.forum.flag_post.reason_inappropriate_label')}</strong>
95-
{app.translator.trans('flarum-flags.forum.flag_post.reason_inappropriate_text', {
96-
a: guidelinesUrl ? <a href={guidelinesUrl} target="_blank" /> : undefined,
97-
})}
95+
{guidelinesUrl
96+
? app.translator.trans('flarum-flags.forum.flag_post.reason_inappropriate_text', {
97+
a: <a href={guidelinesUrl} target="_blank" />,
98+
})
99+
: app.translator.trans('flarum-flags.forum.flag_post.reason_inappropriate_text_no_guidelines')}
98100
{this.reason() === 'inappropriate' && (
99101
<textarea
100102
className="FormControl"

extensions/flags/js/src/forum/forum.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ import './addFlagsDropdown';
55
import './models/Flag';
66

77
import './components/FlagList';
8-
import './components/FlagPostModal';
98
import './components/FlagsPage';
109
import './components/FlagsDropdown';

extensions/flags/locale/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ flarum-flags:
2828
reason_details_placeholder: Additional details (optional)
2929
reason_inappropriate_label: Inappropriate
3030
reason_inappropriate_text: "This post is offensive, abusive, or violates our <a>community guidelines</a>."
31+
reason_inappropriate_text_no_guidelines: This post is offensive or abusive.
3132
reason_missing_message: Please provide some details for our moderators.
3233
reason_off_topic_label: "Off-topic"
3334
reason_off_topic_text: This post is not relevant to the current discussion and should be moved elsewhere.

0 commit comments

Comments
 (0)