Skip to content

Commit 8bb0a03

Browse files
authored
Import sortablejs only once (#25936)
Previously, `sortablejs` was imported twice, once synchronously and once asynchronously, leading to webpack creating duplicate output code (once in the index bundle, and once in a separate chunk). Fix this by always asynchronously importing it. This was one of the build warnings observed when trying to build with vite.
1 parent d0a9456 commit 8bb0a03

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

web_src/js/features/repo-issue-list.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import $ from 'jquery';
22
import {updateIssuesMeta} from './repo-issue.js';
33
import {toggleElem} from '../utils/dom.js';
44
import {htmlEscape} from 'escape-goat';
5-
import {Sortable} from 'sortablejs';
65
import {confirmModal} from './comp/ConfirmModal.js';
76
import {showErrorToast} from '../modules/toast.js';
7+
import {createSortable} from '../modules/sortable.js';
88

99
function initRepoIssueListCheckboxes() {
1010
const $issueSelectAll = $('.issue-checkbox-all');
@@ -176,7 +176,7 @@ async function pinMoveEnd(e) {
176176
});
177177
}
178178

179-
function initIssuePinSort() {
179+
async function initIssuePinSort() {
180180
const pinDiv = document.getElementById('issue-pins');
181181

182182
if (pinDiv === null) return;
@@ -189,7 +189,7 @@ function initIssuePinSort() {
189189
// If only one issue pinned, we don't need to make this Sortable
190190
if (pinDiv.children.length < 2) return;
191191

192-
new Sortable(pinDiv, {
192+
createSortable(pinDiv, {
193193
group: 'shared',
194194
animation: 150,
195195
ghostClass: 'card-ghost',

web_src/js/features/repo-projects.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import $ from 'jquery';
22
import {useLightTextOnBackground} from '../utils/color.js';
33
import tinycolor from 'tinycolor2';
4+
import {createSortable} from '../modules/sortable.js';
45

56
const {csrfToken} = window.config;
67

@@ -55,12 +56,10 @@ async function initRepoProjectSortable() {
5556
const els = document.querySelectorAll('#project-board > .board.sortable');
5657
if (!els.length) return;
5758

58-
const {Sortable} = await import(/* webpackChunkName: "sortable" */'sortablejs');
59-
6059
// the HTML layout is: #project-board > .board > .board-column .board.cards > .board-card.card .content
6160
const mainBoard = els[0];
6261
let boardColumns = mainBoard.getElementsByClassName('board-column');
63-
new Sortable(mainBoard, {
62+
createSortable(mainBoard, {
6463
group: 'board-column',
6564
draggable: '.board-column',
6665
filter: '[data-id="0"]',
@@ -89,7 +88,7 @@ async function initRepoProjectSortable() {
8988

9089
for (const boardColumn of boardColumns) {
9190
const boardCardList = boardColumn.getElementsByClassName('board')[0];
92-
new Sortable(boardCardList, {
91+
createSortable(boardCardList, {
9392
group: 'shared',
9493
animation: 150,
9594
ghostClass: 'card-ghost',

web_src/js/modules/sortable.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export async function createSortable(...args) {
2+
const {Sortable} = await import(/* webpackChunkName: "sortablejs" */'sortablejs');
3+
return new Sortable(...args);
4+
}

0 commit comments

Comments
 (0)