Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use .zip files instead of .data files for loading WordPress #978

Merged
merged 6 commits into from
Jan 29, 2024

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Jan 29, 2024

Playground used the Emscripten's filepacker.py tool to bundle WordPress releases as zip files. This caused a lot of problems:

  • Filepacker splits WordPress into a .data file, with all the bytes concatenated as a single blob, and a .js file with the map of offsets and lengths for each file. Sometimes the browsers would invalidate the cache for the .data file, but not the .js file, causing the playground to fail to load.
  • The .js files had to be patched in the Dockerfile.
  • The .js files used XHR to load the .data files, which required custom error handling logic, progress monitoring logic, and even then some of the errors were not handled properly – see Playground not loading on Android and Chrome #564.
  • The .data loading code required custom loading logic.
  • The .data files were not stream–loaded. This PR doesn't stream-load the .zip files either, but that feature may be added in the future using the new @wp-playground/compression-streams package.

Changes

  • The WordPress build process now produces .zip files instead of .data
    • .js files.
  • The worker thread now loads WordPress from zip files, including zips from arbitrary URLs.
  • Query API and Blueprints now accept URLs via the ?wp= parameter.

Testing instructions

  • Confirm all the E2E tests pass

cc @bgrgicak

Playground used the Emscripten's filepacker.py tool to bundle WordPress
releases as zip files. This caused a lot of problems:

* Filepacker splits WordPress into a `.data` file, with all the bytes
  concatenated as a single blob, and a `.js` file with the map of
  offsets and lengths for each file. Sometimes the browsers would
  invalidate the cache for the `.data` file, but not the `.js` file,
  causing the playground to fail to load.
* The `.js` files had to be patched in the Dockerfile.
* The `.js` files used XHR to load the `.data` files, which required custom
  error handling logic, progress monitoring logic, and even then some of the
  errors were not handled properly – see #504.
* The `.data` loading code required custom loading logic.
* The `.data` files were not stream–loaded. This PR doesn't stream-load the
  `.zip` files either, but that feature may be added in the future using the
  new `@wp-playground/compression-streams` package.

 ## Changes

* The WordPress build process now produces `.zip` files instead of `.data`
  + `.js` files.
* The worker thread now loads WordPress from zip files, including zips from
  arbitrary URLs.
* Query API and Blueprints now accept URLs via the `?wp=` parameter.

 ## Testing instructions

* Confirm all the E2E tests pass
@adamziel adamziel added [Type] Enhancement New feature or request [Type] Developer Experience [Focus] Developer Tools [Type] Reliability Playground uptime, reliability, not crashing labels Jan 29, 2024
@adamziel adamziel mentioned this pull request Jan 29, 2024
@adamziel
Copy link
Collaborator Author

The unit test failure seems intermittent. the last step here would be changing the zipFile step option to a Resource instead of adding a new zipBlob option.

@dmsnell
Copy link
Member

dmsnell commented Jan 29, 2024

this is wonderful! way to go, using common infrastructure to remove a significant chunk of bulk.

@adamziel adamziel merged commit 2f1ceb1 into trunk Jan 29, 2024
5 checks passed
@adamziel adamziel deleted the migrate-to-wp-zip-files branch January 29, 2024 20:59
}
}

// const wordPressFile = fetch(zipFilename);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably not needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good spot!

// Start downloading WordPress if needed
let wordPressRequest = null;
if (!wordPressAvailableInOPFS) {
if (requestedWPVersion.startsWith('http')) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I'm reading this right, we now have support for custom WordPress builds?
Having the ability to prebuild WordPress with additional plugins and themes can be useful for demos like the Woo.com example we explored.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are reading this right indeed! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Developer Tools [Type] Developer Experience [Type] Enhancement New feature or request [Type] Reliability Playground uptime, reliability, not crashing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants