Skip to content

Commit 79452a8

Browse files
committed
fix(input-date-picker): hard to reproduce numbering-system caching issue (#8518)
**Related Issue:** #7958 ## Summary Resolves an extremely hard to reproduce caching issue that occurs due to Alert's timeouts. The fix is to cache Alert's number formatter per component so it doesn't impact other components.
1 parent e99bbf7 commit 79452a8

File tree

1 file changed

+25
-8
lines changed
  • packages/calcite-components/src/components/alert

1 file changed

+25
-8
lines changed

packages/calcite-components/src/components/alert/alert.tsx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
connectLocalized,
3232
disconnectLocalized,
3333
NumberingSystem,
34-
numberStringFormatter,
34+
NumberStringFormat,
3535
} from "../../utils/locale";
3636
import { onToggleOpenCloseComponent, OpenCloseComponent } from "../../utils/openCloseComponent";
3737
import {
@@ -169,10 +169,17 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
169169
connectedCallback(): void {
170170
connectLocalized(this);
171171
connectMessages(this);
172+
172173
const open = this.open;
173174
if (open && !this.queued) {
174175
this.calciteInternalAlertRegister.emit();
175176
}
177+
178+
this.numberStringFormatter.numberFormatOptions = {
179+
locale: this.effectiveLocale,
180+
numberingSystem: this.numberingSystem,
181+
signDisplay: "always",
182+
};
176183
}
177184

178185
async componentWillLoad(): Promise<void> {
@@ -201,12 +208,6 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
201208
}
202209

203210
render(): VNode {
204-
numberStringFormatter.numberFormatOptions = {
205-
locale: this.effectiveLocale,
206-
numberingSystem: this.numberingSystem,
207-
signDisplay: "always",
208-
};
209-
210211
const { open, autoClose, label, placement, queued } = this;
211212
const role = autoClose ? "alert" : "alertdialog";
212213
const hidden = !open;
@@ -265,7 +266,7 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
265266

266267
private renderQueueCount(): VNode {
267268
const queueNumber = this.queueLength > 2 ? this.queueLength - 1 : 1;
268-
const queueText = numberStringFormatter.numberFormatter.format(queueNumber);
269+
const queueText = this.numberStringFormatter.numberFormatter.format(queueNumber);
269270

270271
return (
271272
<div
@@ -402,6 +403,22 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
402403
@Watch("effectiveLocale")
403404
effectiveLocaleChange(): void {
404405
updateMessages(this, this.effectiveLocale);
406+
this.numberStringFormatter.numberFormatOptions = {
407+
locale: this.effectiveLocale,
408+
numberingSystem: this.numberingSystem,
409+
signDisplay: "always",
410+
};
411+
}
412+
413+
@State() numberStringFormatter = new NumberStringFormat();
414+
415+
@Watch("numberingSystem")
416+
numberingSystemChange(): void {
417+
this.numberStringFormatter.numberFormatOptions = {
418+
locale: this.effectiveLocale,
419+
numberingSystem: this.numberingSystem,
420+
signDisplay: "always",
421+
};
405422
}
406423

407424
@State() hasEndActions = false;

0 commit comments

Comments
 (0)