Skip to content
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

More robust implementation of readBreakpoints() #12

Merged
merged 3 commits into from
May 15, 2017

Conversation

megatronCGN
Copy link
Contributor

At least in Firefox 53, the body:after content is updated with the JSON data once a matching media is found in CSS. However, when the viewport is resized and does no longer match any of the defined breakpoints, the .content reverts to 'none', a literal string value. This fails during JSON parsing, effectively leaving the breakpoint unchanged.

I also had the same issue with IE 11. I did not examine any closer there, but that also disappeared with this change.

At least in Firefox 53, the `body:after` content is updated with the JSON data once a matching media is found in CSS. However, when the viewport is resized and does no longer match *any* of the defined breakpoints, the `.content` reverts to `'none'`, a literal string value. This fails during JSON parsing, effectively leaving the `breakpoint` unchanged.

I also had the same issue with IE 11. I did not examine any closer there, but that also disappeared with this change.
@mpdude mpdude mentioned this pull request May 11, 2017
@mpdude
Copy link

mpdude commented May 11, 2017

Although the symptoms are similar to #10, the cause is different.

In FF 53, the breakpoints = false statement is never reached.

@eduardoboucas
Copy link
Owner

First of all, thanks for this! If I understand correctly, JSON.parse() is failing in certain situations causing the script to break. If that's the case, shouldn't we deal with that in the catch block, instead of returning inside the try?

@mpdude
Copy link

mpdude commented May 15, 2017

We'd then have...

function readBreakpoints() {
    if (window.getComputedStyle && (window.getComputedStyle(element, '::after').content !== '')) {
      var data = window.getComputedStyle(element, '::after').content;

      try {
        breakpoints = JSON.parse(removeQuotes(data));
      } catch (err) {
        breakpoints = false;      
      }
    } else { 
      breakpoints = false;
    }
  }

@eduardoboucas if you prefer that, I'll ask @megatronCGN to change it

@eduardoboucas
Copy link
Owner

That would be great, thanks!

@megatronCGN
Copy link
Contributor Author

@eduardoboucas done, you're welcome

include-media.js Outdated
} else {
breakpoints = false;
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

Tiny detail, could you remove the trailing whitespace here?

@eduardoboucas eduardoboucas merged commit 5c83be8 into eduardoboucas:master May 15, 2017
@eduardoboucas
Copy link
Owner

Merged, thank you! I'll release to npm now.

@megatronCGN megatronCGN deleted the patch-1 branch May 15, 2017 09:09
@eduardoboucas
Copy link
Owner

Done, 1.0.3 released. @mpdude could you confirm whether this also closes #11?

@mpdude
Copy link

mpdude commented May 15, 2017

Will do, head over to #11.

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.

3 participants