Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ function loadSettings() {
}
}

const storedChannel = urlParams.get('channel_name') || localStorage.getItem('channel_name');
const urlChannel = urlParams.get('channel_name');
if (urlChannel) {
localStorage.setItem('channel_name', urlChannel);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Sanitize URL channel before persisting

Persisting channel_name directly from query params stores malformed values (for example %20foo or trailing spaces) into localStorage, and loadSettings() then treats that value as ready on future visits, which can repeatedly initialize chat with an invalid channel even when the bad URL is no longer present. This regression is introduced by the new persistence path; unlike the manual save flow, this branch does not trim/normalize before saving.

Useful? React with 👍 / 👎.

}
const storedChannel = urlChannel || localStorage.getItem('channel_name');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the logic is correct, this line is a bit redundant. Since you've just updated localStorage with urlChannel if it exists, you can simplify this by always reading from localStorage. This makes the logic clearer: first update localStorage from the URL if available, then read from localStorage as the single source of truth for the session's setting.

Suggested change
const storedChannel = urlChannel || localStorage.getItem('channel_name');
const storedChannel = localStorage.getItem('channel_name');

const storedRestartTime = urlParams.get('restart_time') || localStorage.getItem('restart_time');
const storedAvatarInput = urlParams.get('win_avatar_enable') || localStorage.getItem('win_avatar_enable');
const storedSoundInput = urlParams.get('sound_enable') || localStorage.getItem('sound_enable');
Expand Down