feat: Add liveReload#1407
Conversation
|
To be decided: Should clients try to reconnect to the server, e.g. in case it has been restarted? This is currently not implemented, but I think it should be added. |
This has now been implemented. |
ff657e6 to
409ab00
Compare
Adds optional live reload support to the server: - New `serveLiveReloadClient` middleware serves the client at `/.ui5/liveReload/client.js`. - The `serveResources` middleware injects the client script tag into HTML responses when `liveReload` is enabled. - A WebSocket server attaches to the HTTP server and notifies connected clients when the BuildServer emits a `sourcesChanged` event. The feature is opt-in via the new `liveReload` option to `serve()` and defaults to `false`. JIRA: CPOUI5FOUNDATION-1224
- Add new `server.settings.liveReload` boolean option to the project configuration schema, available with specVersion 5.0 and higher. - BuildServer now emits a debounced `sourcesChanged` event (100ms debounce) whenever watched source files change, so a burst of changes results in a single notification. JIRA: CPOUI5FOUNDATION-1224
- Add new `--live-reload` CLI flag (defaults to true) for the `ui5 serve` command. Pass `--no-live-reload` to disable it. - The flag overrides the `server.settings.liveReload` setting in the project's `ui5.yaml`. - When neither the CLI flag nor the configuration sets a value, live reload is enabled by default. JIRA: CPOUI5FOUNDATION-1224
| @@ -0,0 +1,108 @@ | |||
| (function() { | |||
There was a problem hiding this comment.
No unit tests for the client code 😿
There was a problem hiding this comment.
I didn't want to introduce real browser tests as I think it might be an overkill. But as it's based on WebSockets, my idea would be to mock the browser deps and run it in Node.js, as we can also connect via WebSocket from there. This would also make the coverage measurements much simpler.
| // const changedResourcePaths = [...changes.values()].flat(); | ||
| // this.emit("sourcesChanged", changedResourcePaths); | ||
| // Debounced emit so a burst of file changes results in a single reload notification | ||
| if (this.#sourcesChangedTimeout) { |
There was a problem hiding this comment.
Since we were talking about this behavior today: Do we have unit tests for this change and the debounce in particular?
JIRA: CPOUI5FOUNDATION-1224