From 3245987113592099ba7671ad37eec76ecc418b29 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Wed, 12 Dec 2018 12:51:06 +0000 Subject: [PATCH] Prevent both sides sharing a download URL. (#369) --- src/components/compress/index.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/compress/index.tsx b/src/components/compress/index.tsx index ea52eb2a..90ad575a 100644 --- a/src/components/compress/index.tsx +++ b/src/components/compress/index.tsx @@ -160,7 +160,7 @@ function stateForNewSourceData(state: State, newSource: SourceImage): State { for (const i of [0, 1]) { // Ditch previous encodings const downloadUrl = state.sides[i].downloadUrl; - if (downloadUrl) URL.revokeObjectURL(downloadUrl!); + if (downloadUrl) URL.revokeObjectURL(downloadUrl); newState = cleanMerge(state, `sides.${i}`, { preprocessed: undefined, @@ -319,9 +319,14 @@ export default class Compress extends Component { private async onCopyToOtherClick(index: 0 | 1) { const otherIndex = (index + 1) % 2; const oldSettings = this.state.sides[otherIndex]; + const newSettings = { ...this.state.sides[index] }; + + // Create a new object URL for the new settings. This avoids both sides sharing a URL, which + // means it can be safely revoked without impacting the other side. + if (newSettings.file) newSettings.downloadUrl = URL.createObjectURL(newSettings.file); this.setState({ - sides: cleanSet(this.state.sides, otherIndex, this.state.sides[index]), + sides: cleanSet(this.state.sides, otherIndex, newSettings), }); const result = await this.props.showSnack('Settings copied across', {