mirror of
https://github.com/discourse/discourse.git
synced 2026-08-04 10:23:17 -05:00
FIX: poll plugin breaking when local-dates plugin is disabled (#36889)
The recent commit (6a7825baf3) that added local date support in poll
options introduced a static import from the discourse-local-dates
plugin. This caused the poll plugin to blow up during initialization
when local-dates was disabled, since the module simply doesn't exist in
that case.
Switched to using `optionalRequire` which safely checks if the module is
available before loading it. This is the same pattern already used by
chat-composer and the core local-dates helper for cross-plugin
dependencies.
This commit is contained in:
@@ -19,12 +19,12 @@ import { removeValueFromArray } from "discourse/lib/array-tools";
|
||||
import { AUTO_GROUPS } from "discourse/lib/constants";
|
||||
import { bind } from "discourse/lib/decorators";
|
||||
import { trackedArray } from "discourse/lib/tracked-tools";
|
||||
import { optionalRequire } from "discourse/lib/utilities";
|
||||
import autoFocus from "discourse/modifiers/auto-focus";
|
||||
import ComboBox from "discourse/select-kit/components/combo-box";
|
||||
import GroupChooser from "discourse/select-kit/components/group-chooser";
|
||||
import { and, not } from "discourse/truth-helpers";
|
||||
import { i18n } from "discourse-i18n";
|
||||
import generateCurrentDateMarkup from "discourse/plugins/discourse-local-dates/lib/generate-current-date-markup";
|
||||
|
||||
export const BAR_CHART_TYPE = "bar";
|
||||
export const PIE_CHART_TYPE = "pie";
|
||||
@@ -376,6 +376,14 @@ export default class PollUiBuilderModal extends Component {
|
||||
(event.metaKey || event.ctrlKey) &&
|
||||
this.siteSettings.discourse_local_dates_enabled
|
||||
) {
|
||||
const generateCurrentDateMarkup = optionalRequire(
|
||||
"discourse/plugins/discourse-local-dates/lib/generate-current-date-markup"
|
||||
);
|
||||
|
||||
if (!generateCurrentDateMarkup) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
const timezone = this.currentUser.user_option?.timezone;
|
||||
const markup = generateCurrentDateMarkup(timezone);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe "Poll UI Builder" do
|
||||
it "loads when local-dates plugin is disabled" do
|
||||
SiteSetting.discourse_local_dates_enabled = false
|
||||
|
||||
visit "/"
|
||||
|
||||
errors =
|
||||
$playwright_logger.logs.select do |log|
|
||||
log[:level] == "error" &&
|
||||
log[:message].include?("/discourse-local-dates/lib/generate-current-date-markup")
|
||||
end
|
||||
|
||||
expect(errors).to be_empty
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user