-
Notifications
You must be signed in to change notification settings - Fork 205
removed INJECTION const that when injected affected certain styles on… #959
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
Changes from 4 commits
5a9df11
07ed794
f5f17ee
a753dc8
e628935
a6620a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| if ('WebSocket' in window) { | ||
| (function () { | ||
| /** | ||
| * Allows to reload the browser when the server connection is lost | ||
| */ | ||
| function tryReload() { | ||
| var request = new XMLHttpRequest(); | ||
| request.open('GET', window.location.href, true); | ||
| request.onreadystatechange = function () { | ||
| if (request.readyState == 4) { | ||
| if (request.status == 0) { | ||
| setTimeout(function () { | ||
| tryReload(); | ||
| }, 1000) | ||
| } else { | ||
| window.location.reload(); | ||
| } | ||
| } | ||
| }; | ||
| request.send(); | ||
| } | ||
|
|
||
| /** | ||
| * Listen server file reload | ||
| */ | ||
| function refreshCSS() { | ||
| var sheets = [].slice.call(document.getElementsByTagName('link')); | ||
| var head = document.getElementsByTagName('head')[0]; | ||
| for (var i = 0; i < sheets.length; ++i) { | ||
| var elem = sheets[i]; | ||
| var rel = elem.rel; | ||
| if (elem.href && typeof rel != 'string' || rel.length == 0 || rel.toLowerCase() == 'stylesheet') { | ||
| head.removeChild(elem); | ||
| var url = elem.href.replace(/(&|\\?)_cacheOverride=\\d+/, ''); | ||
| elem.href = url + (url.indexOf('?') >= 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf()); | ||
| head.appendChild(elem); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; | ||
| var address = protocol + window.location.host + '/client-reload'; | ||
| var socket = new WebSocket(address); | ||
| socket.onmessage = function (msg) { | ||
| if (msg.data == 'reload') { | ||
| tryReload(); | ||
| } else if (msg.data == 'refreshcss') { | ||
| refreshCSS(); | ||
| } | ||
| }; | ||
| socket.onclose = function () { | ||
| tryReload(); | ||
| } | ||
| })(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,3 +30,5 @@ html | |
| script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" | ||
| script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" | ||
| script src="/dist/main.bundle.js" | ||
| - if Amber.env.development? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Talked to @elorest about this. Let's create a new setting for this that we can turn on and off instead of based on which environment you are in. Something like |
||
| script src="/js/amber_reload.js" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| require "../../support/client_reload" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be a pipeline since it doesn't actually modify the request/response in any way. Let's find a way to initialize the socket in the CLI when using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good. |
||
|
|
||
| module Amber | ||
| module Pipe | ||
| # Reload clients browsers using `ClientReload`. | ||
| # | ||
| # NOTE: Amber::Pipe::Reload is intended for use in a development environment. | ||
| # ``` | ||
| # pipeline :web do | ||
| # plug Amber::Pipe::Reload.new | ||
| # end | ||
| # ``` | ||
| class Reload < Base | ||
| def initialize(@env : Amber::Environment::Env = Amber.env) | ||
| Support::ClientReload.new | ||
| end | ||
|
|
||
| def call(context : HTTP::Server::Context) | ||
| call_next(context) | ||
| end | ||
| end | ||
| end | ||
| end | ||
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.
This is where I was saying we could check a variable set by the pipeline.
Then in the layout check if that param exists instead of checking the environment.
What do you think @drujensen