diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index e151462fcb..29b5f9f5ee 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -1224,7 +1224,10 @@ export function generateExpandoInstructionBlock( tView.firstCreatePass, true, 'Expando block should only be generated on first create pass.'); - const elementIndex = -(tNode.index - HEADER_OFFSET); + // Important: In JS `-x` and `0-x` is not the same! If `x===0` then `-x` will produce `-0` which + // requires non standard math arithmetic and it can prevent VM optimizations. + // `0-0` will always produce `0` and will not cause a potential deoptimization in VM. + const elementIndex = HEADER_OFFSET - tNode.index; const providerStartIndex = tNode.providerIndexes & TNodeProviderIndexes.ProvidersStartIndexMask; const providerCount = tView.data.length - providerStartIndex; (tView.expandoInstructions || (tView.expandoInstructions = [