Skip to content

Commit f2baf77

Browse files
committed
feat: avoid reload if actual is the same as the fallback
1 parent 317f014 commit f2baf77

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ const hints = [
6060
${Object.values(hints)
6161
.map((hint) => {
6262
const cookieName = JSON.stringify(hint.cookieName)
63-
return `{ name: ${cookieName}, actual: String(${hint.getValueCode}), cookie: cookies[${cookieName}] }`
63+
return `{ name: ${cookieName}, actual: String(${hint.getValueCode}), value: cookies[${cookieName}] ?? encodeURIComponent("${hint.fallback}") }`
6464
})
6565
.join(',\n')}
6666
];
6767
for (const hint of hints) {
68-
if (decodeURIComponent(hint.cookie) !== hint.actual) {
68+
document.cookie = encodeURIComponent(hint.name) + '=' + encodeURIComponent(hint.actual) + '; Max-Age=31536000; path=/';
69+
if (decodeURIComponent(hint.value) !== hint.actual) {
6970
cookieChanged = true;
70-
document.cookie = encodeURIComponent(hint.name) + '=' + encodeURIComponent(hint.actual) + '; Max-Age=31536000; path=/';
7171
}
7272
}
7373
// if the cookie changed, reload the page, unless the browser doesn't support

0 commit comments

Comments
 (0)