Skip to content

removed INJECTION const that when injected affected certain styles on…#959

Merged
drujensen merged 6 commits into
amberframework:masterfrom
theprogramsam:sh/reloader_fix
Oct 17, 2018
Merged

removed INJECTION const that when injected affected certain styles on…#959
drujensen merged 6 commits into
amberframework:masterfrom
theprogramsam:sh/reloader_fix

Conversation

@theprogramsam
Copy link
Copy Markdown
Contributor

@theprogramsam theprogramsam commented Oct 13, 2018

… page. Extracted reload script to its own js folder to resolve css issues. Added in condition to load script if in development in application layout and routes.

Description of the Change

Amber reload was previously removed due to unknown issues and at least for the projects I worked on in Crystal, it would inadvertently skew certain css stylings when added on the the context.response. By extracting out the JavaScript file into in the public folder, it fixed the issues I was having with the previous code. Due to the extraction, a static socket route is need in order for the JavaScript to know what socket to connect to.

Alternate Designs

Could possibly get a shard that is included by default in amber instead of a pipeline.

Benefits

Codebase and css styling functioned as wanted and were not effected by extra padding and positioning from the injected constant that was previously used.

Possible Drawbacks

May not qualify as a pipeline with the new changes.

… page. Extracted reload script to its own js folder to resolve css issues. Added in condition to load script if in development in application layout and routes.
@drujensen
Copy link
Copy Markdown
Member

@samholst This is great! thanks for working on this. 💯 Is it ready to be reviewed?

@theprogramsam
Copy link
Copy Markdown
Contributor Author

@drujensen Thanks! In just a few it should be ready for review :)

@elorest
Copy link
Copy Markdown
Member

elorest commented Oct 14, 2018

@faustinoaq was working on something similar here: #865

@drujensen @faustinoaq Perhaps we should include the JS file optionally based upon a variable set or added by the reload_pipe to context somehow.

Copy link
Copy Markdown
Member

@elorest elorest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple comments but I think this is great progress. I've added a PR as well just to get the feature back but I'll hold off on merging it as I think this could end up better.

Another option would be to add a string to context which would be empty by default but could be used to inject code into the write parts of the html body.

The problem with injecting it in the beginning or response, is that it's outside of the html body, which works for some reason but has weird implications on style.

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<script src="/dist/main.bundle.js"></script>
<%="<"%>%- if Amber.env.development? -%><script src="/js/amber_reload.js"></script><%="<"%>%- end -%>
Copy link
Copy Markdown
Member

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.

#in reload_pipe
context.params["_auto_reload_"] = "true"
call_next

Then in the layout check if that param exists instead of checking the environment.

What do you think @drujensen

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?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 if Amber.settings.auto_reload?

Comment thread src/amber/pipes/reload.cr Outdated
@@ -0,0 +1,23 @@
require "../../support/client_reload"
Copy link
Copy Markdown
Member

@drujensen drujensen Oct 15, 2018

Choose a reason for hiding this comment

The 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 amber watch. We should look for the same Amber.settings.auto_reload? flag and if it's true then we instantiate the socket.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

…ng in Amber Settings and auto_reload property?
@theprogramsam
Copy link
Copy Markdown
Contributor Author

@elorest @drujensen Ready for review :)

drujensen
drujensen previously approved these changes Oct 16, 2018
Copy link
Copy Markdown
Member

@drujensen drujensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so much better using a setting. Thanks!

@@ -1,3 +1,4 @@
require "../config/*"

Amber::Support::ClientReload.new if Amber.settings.auto_reload?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can use an initializer for this instead of in the main program? wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm for that. Let me make that change real fast.

<% when "sqlite" -%>
database_url: sqlite3:./db/<%= database_name_base %>_development.db
<% end -%>
auto_reload: true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

@@ -0,0 +1 @@
Amber::Support::ClientReload.new if Amber.settings.auto_reload?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Copy link
Copy Markdown
Member

@elorest elorest Oct 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drujensen I feel like initializers are for initializing shards or outside libraries rather than something built into amber. This is how Rails does it.

The fact that this is built into our JS, amber watch, and env settings means that this is clearly not something outside of amber.

Am I wrong here? Personally I though it made more sense in the main project file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree. This is not really core to the framework and is an add-on. It should be easily removed. To your point, maybe the setting should be moved to the custom settings?

@drujensen
Copy link
Copy Markdown
Member

@elorest can we merge this?

Copy link
Copy Markdown
Member

@robacarp robacarp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @samholst

@drujensen drujensen merged commit c9b4b57 into amberframework:master Oct 17, 2018
@drujensen
Copy link
Copy Markdown
Member

I talked to @elorest and we will go with an initializer for now in anticipation for making live_reload an add-on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants