Skip to content

Commit e75263f

Browse files
committed
Dashboard - itables hang
Don’t attempt to replace init if it isn’t present
1 parent 2ca3b1d commit e75263f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/format/dashboard/format-dashboard-tables.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const kStripRegexes = [
1919
// This is the table initialization
2020
const kDatatableInit =
2121
/\$\(document\).ready\(function \(\) \{(?:\s|.)*?\$\('#(.*?)'\)\.DataTable\(dt_args\);(?:\s|.)*?\}\);.*/g;
22+
const kHasDatatableInit = /\.DataTable\(dt_args\);/g;
2223

2324
// The href for the datatable CSS that is injected
2425
const kDtCssHrefRegex =
@@ -58,11 +59,13 @@ export function processDatatables(
5859
if (hasConnectedDt) {
5960
// Replace the table initialization
6061
const codeText = codeFiltered.join("\n");
61-
const codeWithInit = codeText.replace(
62-
kDatatableInit,
63-
"let table = new DataTable('#$1', dt_args);",
64-
);
65-
scriptEl.innerText = codeWithInit;
62+
if (codeText.match(kHasDatatableInit)) {
63+
const codeWithInit = codeText.replace(
64+
kDatatableInit,
65+
"let table = new DataTable('#$1', dt_args);",
66+
);
67+
scriptEl.innerText = codeWithInit;
68+
}
6669

6770
// Remove the inline css
6871
const linkCssNodes = doc.querySelectorAll(

0 commit comments

Comments
 (0)