-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Recommended way to gracefully display a message for unsupported browsers #9062
Comments
Maybe just using proxy polyfill would be easy way out of it - something like https://github.com/GoogleChrome/proxy-polyfill? As for |
Hey, thanks for taking the time to take a look at this. However, Google's polyfill doesn't support all of proxy's traps and unfortunately won't help me. I still have the option to downgrade MobX, but since I don't really care about IE I chose the "display a message" route. But yeah, ideally, a polyfill would have been what I would have chosen. As for HTML comments, React requires a wrapper to use I have researched this a little further since posting this issue, but no good way to do this came up. This is why I geared this question towards "how do I detect browser early on, and chose what top component to render in Gatsby", if this makes any sense ? Ideally, I'd like to be able to run code in the browser as early as |
@Coriou what about just adding a custom script? e.g. in
function Html(props) {
return (
<html {...props.htmlAttributes}>
<head>
<meta charSet="utf-8" />
<meta httpEquiv="x-ua-compatible" content="ie=edge" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<script dangerouslySetInnerHTML={{ __html: `
// note: this needs to go before any JS is loaded, e.g. probably in the head tags?
if (typeof window !== 'undefined' && typeof window.Proxy === 'undefined') {
// do something, e.g.
window.location.replace('/ie.html') // this presumes you set up an ie.html fallback, i.e. a vanilla HTML file you create yourself
}
` }} />
{props.headComponents}
</head>
<body {...props.bodyAttributes}>
{props.preBodyComponents}
<div
key={`body`}
id="___gatsby"
dangerouslySetInnerHTML={{ __html: props.body }}
/>
{props.postBodyComponents}
</body>
</html>
)
}
export default Html |
@pieh also recommended using |
Damn it. Yes, that’s it guys. Just gotta redirect manually to a dummy page using the Thank you very much to both of you ! |
Hey. Just a little follow up on this issue :
I placed a lot of faith in the second approach. It should by all means work if the I feel like I'm closer to solving this, but I'm still missing something here ... |
@Coriou is there a reason the approach I posted won't work? It seems pretty clear that that snippet will execute before any other JS executes, and will therefore work exactly like you want? I just tested it out, and it it seems like that script executes like you'd want and works appropriately. |
@DSchau I’ll give this exact approach a try tomorrow, you’re right it might just work... sorry for wasting your time. I’ll let you know |
Indeed, it just works... Thanks a lot ! |
@chocobuckle You can generate it using the build hooks of Gatsby. In my case, I created the HTML page and using the // gatsby-node.js
exports.onPostBootstrap = () => {
let iePage = path.resolve("./src/ie.html"),
iePublicPath = path.resolve("./public/ie.html")
if (fs.existsSync(iePage))
fs.createReadStream(iePage).pipe(fs.createWriteStream(iePublicPath))
} Making the |
@Coriou Thanks for the explanation. All working perfectly. |
I'm using MobX 5 in my Gatsby app, which requires proxy support and thus it'll simply throw an error and crash on IE (all versions). I don't care at all about IE (nor Edge actually), but I still don't want my users to see an empty page when they try to access my app from one of those browsers.
I've tried a couple of different approaches, but they all seemed hacky and unpleasant.
What's the best way to display a message for these users ? I reckon it has to be done at the lowest (or earliest) stage possible, as MobX will crash JS right after it's been imported (and I import in in my layout component of course).
I considered using conditional HTML comments in my
html.js
file ([If !IE]...
), and serve a specific bundle to those users, but that proved to be quite challenging because React doesn't really allow this in a simple fashion.I have a feeling the key is in
html.js
but I can't quite figure it out. I'm pretty sure other people wanted to achieve something similar, any tips ?The text was updated successfully, but these errors were encountered: