This repository has been archived by the owner on Feb 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 646
Live reloading #193
Closed
Closed
Live reloading #193
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
a1921de
Initial rough implementation, hardcoded always to be on, and at a fix…
SteveSandersonMS dba8437
Enable live reloading only for debug builds.
SteveSandersonMS 381ac3d
Fix tests
SteveSandersonMS 9ebdc1a
Add E2E tests
SteveSandersonMS f395114
E2E fixes
SteveSandersonMS c55c19a
Keep reload signals within the context of an individual UseBlazorLive…
SteveSandersonMS c818cd9
Remove unnecessary reload delay
SteveSandersonMS df12cfb
Revert "Remove unnecessary reload delay"
SteveSandersonMS 096aecb
Avoid spurious error message in Firefox
SteveSandersonMS e791265
Post-rebase fixes
SteveSandersonMS a508168
Update build-completed signal to match new build mechanism
SteveSandersonMS cbf44cc
Add missing assertion that was lost during rebase
SteveSandersonMS a1d3258
Fix live reloading E2E test following build mechanism changes
SteveSandersonMS a3def66
Make live reloading easier to turn on/off
SteveSandersonMS 37ab3cd
Enable live reloading on test app when running in CI
SteveSandersonMS d38e085
Make reload URI less likely to clash with an application path
SteveSandersonMS 0984189
Don't issue the reload notification until the build is really finished
SteveSandersonMS 0afe9dd
Post-rebase fixes
SteveSandersonMS 6c7ee54
Allow longer for E2E test to complete
SteveSandersonMS ed4fa10
Remove unnecessary "reload on server disconnection" feature, since we…
SteveSandersonMS 6223599
Clean up
SteveSandersonMS cef1d9f
Cause 'dotnet watch' to respond to .cshtml file changes
SteveSandersonMS d00b9ae
Don't issue reload notifications when building inside VS. This needs …
SteveSandersonMS 8c876d6
Switch from EventSource to WebSocket for live reloading notifications
SteveSandersonMS f18e396
On the server, ensure live reloading is never enabled in the Producti…
SteveSandersonMS 7893896
Always run Live Reloading E2E tests in Development environment
SteveSandersonMS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/Microsoft.AspNetCore.Blazor.Browser.JS/src/LiveReloading.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const reconnectionPollIntervalMs = 250; | ||
|
||
export function enableLiveReloading(endpointUri: string) { | ||
listenForReloadEvent(endpointUri); | ||
} | ||
|
||
function listenForReloadEvent(endpointUri: string) { | ||
if (!WebSocket) { | ||
console.log('Browser does not support WebSocket, so live reloading will be disabled.'); | ||
return; | ||
} | ||
|
||
// First, connect to the endpoint | ||
const websocketUri = toAbsoluteWebSocketUri(endpointUri); | ||
const source = new WebSocket(websocketUri); | ||
let allowConnectionFailedErrorReporting = true; | ||
|
||
source.onopen = e => { | ||
allowConnectionFailedErrorReporting = false; | ||
}; | ||
|
||
source.onerror = e => { | ||
if (allowConnectionFailedErrorReporting) { | ||
allowConnectionFailedErrorReporting = false; | ||
console.error(`The client app was compiled with live reloading enabled, but could not open ` | ||
+ ` a WebSocket connection to the server at ${websocketUri}\n` | ||
+ `To fix this inconsistency, either run the server in development mode, or compile the ` | ||
+ `client app in Release configuration.`); | ||
} | ||
}; | ||
|
||
// If we're notified that we should reload, then do so | ||
source.onmessage = e => { | ||
if (e.data === 'reload') { | ||
location.reload(); | ||
} | ||
}; | ||
} | ||
|
||
function toAbsoluteWebSocketUri(uri: string) { | ||
const baseUri = document.baseURI; | ||
if (baseUri) { | ||
const lastSlashPos = baseUri.lastIndexOf('/'); | ||
const prefix = baseUri.substr(0, lastSlashPos); | ||
uri = prefix + uri; | ||
} | ||
|
||
// Scheme must be ws: or wss: | ||
return uri.replace(/^http/, 'ws'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the work that billhie is going for us? Or will we need to add something ourselves?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bill is doing some work to avoid the unwanted IISExpress recycles - it's related to this work item, but not to this comment.
We will have to do some work in our VS extension ourselves to detect when a build completes and write the signal file. I was expecting to do that, though I may have to ask for your advice on it since I have no experience of writing any VS extension code.