Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

0.13.0 - HMR seems to be firing as server reloads #277

Closed
btakita opened this issue Jun 2, 2018 · 4 comments
Closed

0.13.0 - HMR seems to be firing as server reloads #277

btakita opened this issue Jun 2, 2018 · 4 comments

Comments

@btakita
Copy link
Contributor

btakita commented Jun 2, 2018

I'm getting a timeout error with the HMR *.hot-update.json request.

sapper-hmr-reload-bug

I was able to fix the issue by adding a timeout to check in sapper-dev-client.js

setTimeout(() => check(), 250) instead of check() in the connect method.

export function connect(port) {
	if (source || !window.EventSource) return;

	source = new EventSource(`http://${window.location.hostname}:${port}/__sapper__`);

	window.source = source;

	source.onopen = function(event) {
		console.log(`[SAPPER] dev client connected`);
	};

	source.onerror = function(error) {
		console.error(error);
	};

	source.onmessage = function(event) {
		const data = JSON.parse(event.data);
		if (!data) return; // just a heartbeat

		if (data.action === 'reload') {
			window.location.reload();
		}

		if (data.status === 'completed') {
			setTimeout(() => check(), 250)
		}
	};
}
@btakita
Copy link
Contributor Author

btakita commented Jun 2, 2018

Here's the network output, in which the connection hangs:

sapper-hmr-reload-bug2

@btakita
Copy link
Contributor Author

btakita commented Jun 2, 2018

The timeout is a kludge as it's dependent on the timing of the restart. Perhaps there could be a way to keep a proxy service up while the development service is restarting?

@Rich-Harris
Copy link
Member

Perhaps there could be a way to keep a proxy service up while the development service is restarting?

I think that's the best solution, yeah

@Rich-Harris
Copy link
Member

The HMR thing is fixed in recent versions, so I'll close this, though in the longer term it might still be good to keep a server up and running between builds

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants