Repository: tkh44/emotion
Pull request #89 (2017-07-05 00:32:57)

Fix ids not being extracted in SSR
<!--
Thanks for your interest in the project. I appreciate bugs filed and PRs submitted!

Please make sure that you are familiar with and follow the Code of Conduct for
this project (found in the CODE_OF_CONDUCT.md file).

Also, please make sure you're familiar with and follow the instructions in the
contributing guidelines (found in the CONTRIBUTING.md file).

If you're new to contributing to open source projects, you might find this free
video course helpful: http://kcd.im/pull-request

Please fill out the information below to expedite the review and (hopefully)
merge of your pull request!
-->

<!-- What changes are being made? (What feature/bug is being fixed here?) -->
**What**:

<!-- Why are these changes necessary? -->
**Why**:

<!-- How were these changes implemented? -->
**How**:

Fix the regex in `extractCritical` so that it extracts the last hash in a class name.

<!-- Have you done all of these things?  -->
**Checklist**:
<!-- add "N/A" to the end of each line that's irrelevant to your changes -->
<!-- to check an item, place an "x" in the box like so: "- [x] Documentation" -->
- [ ] Documentation N/A
- [x] Tests
- [x] Code complete

<!-- feel free to add additional comments -->

~~This also reverts 633cf73e4fbdf266ae5e614289faf5abe16a66bf because the snapshot that this updates has not changed on Travis or my machine~~


Closes #89 

codecov-io: # [Codecov](https://codecov.io/gh/tkh44/emotion/pull/89?src=pr&el=h1) Report
> Merging [#89](https://codecov.io/gh/tkh44/emotion/pull/89?src=pr&el=desc) into [master](https://codecov.io/gh/tkh44/emotion/commit/633cf73e4fbdf266ae5e614289faf5abe16a66bf?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/tkh44/emotion/pull/89/graphs/tree.svg?src=pr&token=B1bWuYNE2t&width=650&height=150)](https://codecov.io/gh/tkh44/emotion/pull/89?src=pr&el=tree)

```diff
@@          Coverage Diff           @@
##           master     #89   +/-   ##
======================================
  Coverage    88.4%   88.4%           
======================================
  Files          15      15           
  Lines         569     569           
  Branches      118     118           
======================================
  Hits          503     503           
  Misses         53      53           
  Partials       13      13
```


| [Impacted Files](https://codecov.io/gh/tkh44/emotion/pull/89?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/server.js](https://codecov.io/gh/tkh44/emotion/pull/89?src=pr&el=tree#diff-c3JjL3NlcnZlci5qcw==) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/tkh44/emotion/pull/89?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/tkh44/emotion/pull/89?src=pr&el=footer). Last update [633cf73...97f721c](https://codecov.io/gh/tkh44/emotion/pull/89?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/server.js b/src/server.js
index 51efe17f..5c442086 100644
--- a/src/server.js
+++ b/src/server.js
@@ -4,7 +4,7 @@ export function extractCritical (html) {
   // parse out ids from html
   // reconstruct css/rules/cache to pass
   let o = { html, ids: [], css: '', rules: [] }
-  let regex = /css-([a-zA-Z0-9]+)/gm
+  let regex = /css(?:[a-zA-Z0-9-]*)-([a-zA-Z0-9]+)/gm
   let match
   let ids = {}
   while ((match = regex.exec(html)) !== null) {
@@ -14,7 +14,7 @@ export function extractCritical (html) {
   }
 
   o.rules = sheet.sheet.cssRules.filter(x => {
-    let regex = /css-([a-zA-Z0-9]+)/gm
+    let regex = /css(?:[a-zA-Z0-9-]*)-([a-zA-Z0-9]+)/gm
     let match = regex.exec(x.cssText)
     if (match && ids[match[1] + '']) {
       return true


Test patch:
diff --git a/test/__snapshots__/server.test.js.snap b/test/__snapshots__/server.test.js.snap
index 2f8c6e6e..a1135c47 100644
--- a/test/__snapshots__/server.test.js.snap
+++ b/test/__snapshots__/server.test.js.snap
@@ -23,7 +23,12 @@ Object {
   width: 50px;
   background-color: red }",
   "html": "<main class=\\"css-Main-17vxl0k-1g2c78b css-Main-17vxl0k\\" data-reactroot=\\"\\" data-reactid=\\"1\\" data-react-checksum=\\"-2053673081\\"><img size=\\"30\\" class=\\"css-Image-1d2rnu3-1tqe2cj css-Image-1d2rnu3\\" data-reactid=\\"2\\"/><img size=\\"100\\" class=\\"css-Image-1d2rnu3-1rejdxz css-Image-1d2rnu3\\" data-reactid=\\"3\\"/><img class=\\"css-Image-1d2rnu3-1d9ph5s css-Image-1d2rnu3\\" data-reactid=\\"4\\"/></main>",
-  "ids": Array [],
+  "ids": Array [
+    "1g2c78b",
+    "1tqe2cj",
+    "1rejdxz",
+    "1d9ph5s",
+  ],
   "rules": Array [
     Object {
       "cssText": ".no-prefix {