Skip to content

Fix corrupt zip download from Site Editor export - #2531

Merged
brandonpayton merged 5 commits into
trunkfrom
fix-binary-php-response
Aug 21, 2025
Merged

brandonpayton merged 5 commits into
trunkfrom
fix-binary-php-response

Conversation

@brandonpayton

@brandonpayton brandonpayton commented Aug 20, 2025 •

Copy link
Copy Markdown
Member

Motivation for the change, related issues

The purpose of this PR is to fix the corrupt zip download from the Site Editor "Export" feature.

Fixes #2528

Implementation details

This PR adds a stdoutBytes property to StreamedPHPResponse and updates PHPResponse.fromStreamedResponse() to use that.

Prior to this change, fromStreamedResponse() used the stdoutText property which took a byte stream that was decoded on the fly to text and then re-encoded by the accessor to bytes. The bytes of a zip file going through that transform were being corrupted. Without that transform, the zip file bytes are not corrupted.

Testing Instructions (or ideally a Blueprint)

  • Automated: CI
  • Manual
    • Run npx nx unbuilt-asyncify playground-cli -- server
    • Open the site in a browser
    • Navigate to the Site Editor
    • Open the upper-right hamburger menu and click the "Export" menu item to download a theme export zip.
    • Confirm that the downloaded zip can be extracted and that the contents do not look obviously broken.

@brandonpayton brandonpayton self-assigned this Aug 20, 2025
@brandonpayton brandonpayton added [Type] Bug An existing feature does not function as intended [Package][@php-wasm] Universal labels Aug 20, 2025
@brandonpayton

Copy link
Copy Markdown
Member Author

If we stop decoding and encoding stdout as part of the streamed PHP response (as in 04c8eba), the download corruption is no longer an issue.

It seems like PHPResponse or the streamed response should just be relaying the bytes and the headers, and the consumer of the response can decide how to handle the bytes.

@brandonpayton
brandonpayton requested a review from a team August 21, 2025 04:13
@brandonpayton
brandonpayton marked this pull request as ready for review August 21, 2025 04:14
@brandonpayton

Copy link
Copy Markdown
Member Author

@adamziel, since all tests pass and this looks good to me, I'll merge it, but please @-mention me if we need to take another approach. Thank you!

@brandonpayton
brandonpayton merged commit a16fdd8 into trunk Aug 21, 2025
@brandonpayton
brandonpayton deleted the fix-binary-php-response branch August 21, 2025 17:51
}
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started to look at this PR yesterday afternoon, but then had to go. However, I thought there was a one-liner to do this, or at least a simple way, and now I found it:

const bytes = await new Response(stream).bytes();

It might be worth considering for the simplicity of that code.

@brandonpayton brandonpayton Aug 27, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const bytes = await new Response(stream).bytes();

@JanJakes Nice and thank you, I hadn't considered that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package][@php-wasm] Universal [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Site Editor export zip is corrupted

2 participants