Skip to content

feat: Adding insert option #495

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

Conversation

ScriptedAlchemy
Copy link
Contributor

@ScriptedAlchemy ScriptedAlchemy commented Jan 19, 2020

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

In Safari the whole rendering would be suspended while style, added to the head, is loading.
Adding style to the body resolves the problem.

This PR gives users the ability to inject async styles into a specified location

Breaking Changes

none

Additional Info

Fix: #492 #459

@ScriptedAlchemy ScriptedAlchemy requested review from sokra and alexander-akait and removed request for sokra January 19, 2020 01:54
@codecov
Copy link

codecov bot commented Jan 19, 2020

Codecov Report

Merging #495 into master will decrease coverage by 0.15%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #495      +/-   ##
==========================================
- Coverage   88.49%   88.34%   -0.16%     
==========================================
  Files           5        5              
  Lines         426      429       +3     
  Branches       94       97       +3     
==========================================
+ Hits          377      379       +2     
- Misses         47       48       +1     
  Partials        2        2              
Impacted Files Coverage Δ
src/index.js 87.55% <66.66%> (-0.30%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1ffc393...22a9ed2. Read the comment docs.

@ScriptedAlchemy
Copy link
Contributor Author

This resolves async issues when loading CSS. Causing WebKit based browsers to block the render until styles are added to the head.

insert option will default to the head, you can choose another location either with a string body or a function which is passed into the plugin at compile time

@ScriptedAlchemy
Copy link
Contributor Author

@evilebottnawi - Looks like it failed on commit lint, i did reword it but doesn't appear to fix it in CI. All tests and lints are passing

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

One note

@ScriptedAlchemy
Copy link
Contributor Author

@evilebottnawi Bumping on this PR

@alexander-akait
Copy link
Member

Something broken with CI 😕

@ScriptedAlchemy
Copy link
Contributor Author

@evilebottnawi found the problem! CI seems to be working now

@ScriptedAlchemy
Copy link
Contributor Author

@evilebottnawi good enough to merge or is there a CI failure I’m causing?

@alexander-akait
Copy link
Member

I will look at this today/tomorrow and fix the problem with CI, good work, thanks


> ⚠ Do not forget that this code will run in the browser alongside your application. Since not all browsers support latest ECMA features like `let`, `const`, `arrow function expression` and etc we recommend you to use only ECMA 5 features and syntax.

> ⚠ The `insert` function is serialized to string and passed to the plugin. This means that it won't have access to the scope of the webpack configuration module.
Copy link
Member

Choose a reason for hiding this comment

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

I find this a bit weird and think this could be confusing the users.

Doesn't something simple like insert: "head" | "body" fulfill the use case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initially, I supported both use cases. I can reapply that work?

Copy link
Member

Choose a reason for hiding this comment

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

hm, maybe insert: "head" | "querySelector" | Function, querySelector can be body/#head/.class/etc

Copy link

@giuseppeg giuseppeg May 29, 2020

Choose a reason for hiding this comment

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

@sokra I started to work on this feature because I needed to be able to control the insertion bits, specifically inject inside an iframe.

@evilebottnawi's suggestion sounds good to me. Can we merge this PR?

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.

Styles should not be inserted into HEAD in Safari
4 participants