Skip to content

Commit 3430251

Browse files
crisbetoalxhub
authored andcommitted
fix(core): i18n flags leaking on errors
The i18n sub-system has the `changeMask` and `changeMaskCounter` flags which are set by i18n-related instructions and reset once the state is applied. The problem is that if something throws within the application logic, the flags would never be reset. This is currently causing flakes in our CI runs. These changes resolve the issue by adding a try/finally around the flags. (cherry picked from commit 6339d26)
1 parent ce7a43a commit 3430251

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

packages/core/src/render3/i18n/i18n_apply.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,22 @@ export function setMaskBit(hasChange: boolean) {
101101
}
102102

103103
export function applyI18n(tView: TView, lView: LView, index: number) {
104-
if (changeMaskCounter > 0) {
105-
ngDevMode && assertDefined(tView, `tView should be defined`);
106-
const tI18n = tView.data[index] as TI18n | I18nUpdateOpCodes;
107-
// When `index` points to an `ɵɵi18nAttributes` then we have an array otherwise `TI18n`
108-
const updateOpCodes: I18nUpdateOpCodes = Array.isArray(tI18n)
109-
? (tI18n as I18nUpdateOpCodes)
110-
: (tI18n as TI18n).update;
111-
const bindingsStartIndex = getBindingIndex() - changeMaskCounter - 1;
112-
applyUpdateOpCodes(tView, lView, updateOpCodes, bindingsStartIndex, changeMask);
104+
try {
105+
if (changeMaskCounter > 0) {
106+
ngDevMode && assertDefined(tView, `tView should be defined`);
107+
const tI18n = tView.data[index] as TI18n | I18nUpdateOpCodes;
108+
// When `index` points to an `ɵɵi18nAttributes` then we have an array otherwise `TI18n`
109+
const updateOpCodes: I18nUpdateOpCodes = Array.isArray(tI18n)
110+
? (tI18n as I18nUpdateOpCodes)
111+
: (tI18n as TI18n).update;
112+
const bindingsStartIndex = getBindingIndex() - changeMaskCounter - 1;
113+
applyUpdateOpCodes(tView, lView, updateOpCodes, bindingsStartIndex, changeMask);
114+
}
115+
} finally {
116+
// Reset changeMask & maskBit to default for the next update cycle
117+
changeMask = 0b0;
118+
changeMaskCounter = 0;
113119
}
114-
// Reset changeMask & maskBit to default for the next update cycle
115-
changeMask = 0b0;
116-
changeMaskCounter = 0;
117120
}
118121

119122
function createNodeWithoutHydration(
@@ -237,7 +240,7 @@ export function applyCreateOpCodes(
237240
* @param lView Current `LView`
238241
* @param anchorRNode place where the i18n node should be inserted.
239242
*/
240-
export function applyMutableOpCodes(
243+
function applyMutableOpCodes(
241244
tView: TView,
242245
mutableOpCodes: IcuCreateOpCodes,
243246
lView: LView,
@@ -394,7 +397,7 @@ export function applyMutableOpCodes(
394397
* @param changeMask Each bit corresponds to a `ɵɵi18nExp` (Counting backwards from
395398
* `bindingsStartIndex`)
396399
*/
397-
export function applyUpdateOpCodes(
400+
function applyUpdateOpCodes(
398401
tView: TView,
399402
lView: LView,
400403
updateOpCodes: I18nUpdateOpCodes,

0 commit comments

Comments
 (0)