Skip to content

Conversation

@adamziel
Copy link
Collaborator

Makes the WordPress data module reject the loading promise on XHR error. Before this commit, the promise would erroneously resolve even if the request failed.

Related to #564

Testing Instructions

Rebuild the WordPress data module as follows:

node packages/playground/wordpress/build/build.js --wp-version=latest --output-js=packages/playground/wordpress/src/wordpress --output-assets=packages/playground/wordpress/public

Then make the following update to the wp-6.4.js file:

// import dependencyFilename from './wp-6.4.data?url';
const dependencyFilename = 'http://localhost:3000/assets/wp-6.4-1d0e58cc.data';
export { dependencyFilename };

Then create a new file called server.js with the following contents:

// Serve static assets from dist/packages/playground/wasm-wordpress-net/, but
// break the connection when the file is 90% downloaded

const express = require('express');
const app = express();
const path = require('path');
const fs = require('fs');

const port = 3000;

app.get('/*', (req, res) => {
	const filePath = path.join(
		__dirname,
		'dist/packages/playground/wasm-wordpress-net/' + (req.query.path || 'index.html')
	);
	const stat = fs.statSync(filePath);
	const fileSize = stat.size;

	const head = {
		'Content-Length': fileSize,
        'Content-Type': 'application/wasm',
        'Access-Control-Allow-Origin': '*',
	};
	res.writeHead(200, head);
	let sentSoFar = 0;
	const stream = fs.createReadStream(filePath);
	stream.on('data', (chunk) => {
		if (sentSoFar + chunk.length > fileSize * 0.9) {
			stream.destroy();
			res.end();
			return;
		}
        res.write(chunk);
		sentSoFar += chunk.length;
	});
});

app.listen(port, () => console.log(`Example app listening on port ${port}!`));

Then run node server.js and npm run dev and go to http://localhost:5400/website-server/

You'll land in a version of Playground where only the first ~90% of the WordPress data module is downloaded and then the connection is cut. You should see the "oops, WordPress Playground had a hiccup" error message.

Makes the WordPress data module reject the loading promise on XHR error.
Before this commit, the promise would erroneously resolve even if the
request failed.

Related to #564
@adamziel adamziel merged commit 70c2f6e into trunk Jan 17, 2024
@adamziel adamziel deleted the wp-data-module-reject-on-error branch January 17, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant