Skip to content

Commit

Permalink
fix(polyfill): fixes a caching issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Feb 7, 2019
1 parent 5261d13 commit 964449f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/util/polyfill/polyfill-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function getPolyfillIdentifier(name: IPolyfillFeature | IPolyfillFeatureI
const shasum = createHash("sha1");
const normalizedName = name instanceof Set ? name : new Set([name]);
const sortedName = [...normalizedName].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
const namePart = sortedName.map(part => `${part.name}${JSON.stringify(part.meta)}`).join(",");
const namePart = sortedName.map(part => `${part.name}${JSON.stringify(part.meta)}${part.context}`).join(",");
shasum.update(`[${namePart}].${encoding == null ? "" : encoding}`);
return shasum.digest("hex");
}
Expand All @@ -62,7 +62,7 @@ export function getPolyfillIdentifier(name: IPolyfillFeature | IPolyfillFeatureI
export function getPolyfillSetIdentifier(polyfills: Set<IPolyfillFeatureInput>, userAgent: string): string {
const shasum = createHash("sha1");
const sortedName = [...polyfills].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
const namePart = sortedName.map(part => `${part.name}${JSON.stringify(part.meta)}${JSON.stringify(part.force)}`).join(",");
const namePart = sortedName.map(part => `${part.name}${JSON.stringify(part.meta)}${JSON.stringify(part.force)}${JSON.stringify(part.context)}`).join(",");
shasum.update(`[${namePart}].${userAgent}`);
return shasum.digest("hex");
}
Expand Down Expand Up @@ -130,6 +130,7 @@ function getRequiredPolyfillsForUserAgent(polyfillSet: Set<IPolyfillFeatureInput
const existingIndex = polyfillNameToPolyfillIndexMap.get(polyfill.name);
if (existingIndex != null) {
polyfills[existingIndex].meta = polyfill.meta;
polyfills[existingIndex].context = polyfill.context;
} else {
polyfills.push({name: polyfill.name, meta: polyfill.meta, context: polyfill.context});
polyfillNameToPolyfillIndexMap.set(polyfill.name, currentIndex++);
Expand Down
10 changes: 7 additions & 3 deletions test/server/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,22 @@ test("Will correctly parse meta information for Zone. #1", async t => {
t.true([...polyfillRequest.features].some(({meta, name}) => name === "zone" && meta != null && meta.error === true));
});

test("Will set a 'x-applied-polyfills' header on HTTP2 responses with a HTTP-friendly list of all applied polyfills. #1", async t => {
test.only("Will set a 'x-applied-polyfills' header on HTTP2 responses with a HTTP-friendly list of all applied polyfills. #1", async t => {
const result = await sendRequest({
http2: config.http2,
tls: true,
userAgent: ie("11"),
userAgent: chrome("73"),
method: "GET",
host: config.host,
port: config.port,
path: `${constant.endpoint.polyfill}?features=event,custom-event,zone,es.promise.finally,pointer-event|force,systemjs|variant=system,intl|force|locale=en~da&context=node`,
path: `${constant.endpoint.polyfill}?features=requestanimationframe|force`,
acceptEncoding: undefined
});

if ("body" in result) {
console.log(result.body);
}

t.true(result.polyfillsHeader != null);
});

Expand Down

0 comments on commit 964449f

Please sign in to comment.