See comment above at line 703 to see how `generatedId` can be `undefined`