Skip to content

Commit e62ddff

Browse files
committed
fix(ui): ensure init() always executes for toggle button initialization
document.currentScript can be null in ES6 modules, which prevented init() from running on index and reset-password pages, leaving toggle buttons without event listeners. Changes: - Remove conditional check around init() call - Use optional chaining (?.) for safe data attribute access - Always call init() even if currentScript is null - Toggles now work on all pages consistently This fixes the broken theme and density toggle buttons on the main password change page and reset password page.
1 parent 10b9822 commit e62ddff

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

internal/web/static/js/app-init.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@
66
import { init } from "./app.js";
77

88
// Get the current script element to read data attributes
9+
// Note: document.currentScript can be null in ES6 modules, so we provide fallback
910
const currentScript = document.currentScript as HTMLScriptElement | null;
1011

11-
if (currentScript) {
12-
// Read configuration from data attributes
13-
const config = {
14-
minLength: Number(currentScript.dataset["minLength"] ?? "8"),
15-
minNumbers: Number(currentScript.dataset["minNumbers"] ?? "0"),
16-
minSymbols: Number(currentScript.dataset["minSymbols"] ?? "0"),
17-
minUppercase: Number(currentScript.dataset["minUppercase"] ?? "0"),
18-
minLowercase: Number(currentScript.dataset["minLowercase"] ?? "0"),
19-
passwordCanIncludeUsername: currentScript.dataset["passwordCanIncludeUsername"] === "true"
20-
};
12+
// Read configuration from data attributes with defaults
13+
const config = {
14+
minLength: Number(currentScript?.dataset["minLength"] ?? "8"),
15+
minNumbers: Number(currentScript?.dataset["minNumbers"] ?? "0"),
16+
minSymbols: Number(currentScript?.dataset["minSymbols"] ?? "0"),
17+
minUppercase: Number(currentScript?.dataset["minUppercase"] ?? "0"),
18+
minLowercase: Number(currentScript?.dataset["minLowercase"] ?? "0"),
19+
passwordCanIncludeUsername: currentScript?.dataset["passwordCanIncludeUsername"] === "true"
20+
};
2121

22-
// Initialize the app with configuration
23-
init(config);
24-
}
22+
// Initialize the app with configuration (always call, even with defaults)
23+
init(config);

internal/web/static/js/reset-password-init.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
import { init } from "./reset-password.js";
77

88
// Get the current script element to read data attributes
9+
// Note: document.currentScript can be null in ES6 modules, so we provide fallback
910
const currentScript = document.currentScript as HTMLScriptElement | null;
1011

11-
if (currentScript) {
12-
// Read configuration from data attributes
13-
const config = {
14-
minLength: Number(currentScript.dataset["minLength"] ?? "8"),
15-
minNumbers: Number(currentScript.dataset["minNumbers"] ?? "0"),
16-
minSymbols: Number(currentScript.dataset["minSymbols"] ?? "0"),
17-
minUppercase: Number(currentScript.dataset["minUppercase"] ?? "0"),
18-
minLowercase: Number(currentScript.dataset["minLowercase"] ?? "0")
19-
};
12+
// Read configuration from data attributes with defaults
13+
const config = {
14+
minLength: Number(currentScript?.dataset["minLength"] ?? "8"),
15+
minNumbers: Number(currentScript?.dataset["minNumbers"] ?? "0"),
16+
minSymbols: Number(currentScript?.dataset["minSymbols"] ?? "0"),
17+
minUppercase: Number(currentScript?.dataset["minUppercase"] ?? "0"),
18+
minLowercase: Number(currentScript?.dataset["minLowercase"] ?? "0")
19+
};
2020

21-
// Initialize with configuration
22-
init(config);
23-
}
21+
// Initialize with configuration (always call, even with defaults)
22+
init(config);

0 commit comments

Comments
 (0)