Skip to content

Commit d64ba0d

Browse files
authored
fix(performance): ImageDelivery insight errors (#144)
This fixes the ImageDelivery insight which throws when we try to generate it because of its dependency on core/i18n. The long term fix here is to remove the reliance of models/trace on the core/i18n package, or at least dependency inject it, but this is a quick fix to at least make this insight available. The irony is that we don't even use the string in the AI output; but if we don't have the method available we cannot generate the insight. This fixes part of #124 by making this insight not error. The other required work for that bug is to deal with Insights that do error. That work is done in DevTools, but we need to ship & roll a new version into the MCP server.
1 parent 44cfc8f commit d64ba0d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

scripts/post-build.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,30 @@ export const TimeUtilities = {
101101
}
102102
}
103103
104+
return parts.map(part => part.value).join('');
105+
}
106+
};
107+
108+
// TODO(jacktfranklin): once the ImageDelivery insight does not depend on this method, we can remove this stub.
109+
export const ByteUtilities = {
110+
bytesToString(x) {
111+
const separator = '\xA0';
112+
const formatter = new Intl.NumberFormat('en-US', {
113+
style: 'unit',
114+
unit: 'kilobyte',
115+
unitDisplay: 'narrow',
116+
minimumFractionDigits: 1,
117+
maximumFractionDigits: 1,
118+
});
119+
const parts = formatter.formatToParts(x / 1000);
120+
for (const part of parts) {
121+
if (part.type === 'literal') {
122+
if (part.value === ' ') {
123+
part.value = separator;
124+
}
125+
}
126+
}
127+
104128
return parts.map(part => part.value).join('');
105129
}
106130
};`;

0 commit comments

Comments
 (0)