-
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
Issues with domready—animation flickering on page load. #3067
Comments
Yes I've been looking into this for the past two days. I have the same symptoms - keyframes get triggered twice on initial load. What I have noticed so far is:
|
@PiotrF your animation keyframe runs twice when google analytics runs: Request URL:https://www.google-analytics.com/r/collect?v=1&_v=j66&a=1842669742&t=pageview&_s=1&dl=https%3A%2F%2Fpiotrf.pl%2F&dr=https%3A%2F%2Fgithub.com%2Fgatsbyjs%2Fgatsby%2Fissues%2F3067&dp=%2F&ul=en-gb&de=UTF-8&dt=Piotr%20F.%20%E2%80%94%20Product%20designer%20%26%20front-end%20developer%E2%80%94An%20overall%20full-stack%20UX%20design%20specialist&sd=24-bit&sr=1024x1366&vp=1024x1366&je=0&_u=QACAAEAB~&jid=1921053810&gjid=1402211187&cid=1278082317.1511965245&tid=UA-22031199-1&_gid=784946713.1511965245&_r=1&z=209848835 |
@migs540 I can confirm that your sample seems to be suffering from the very same issue I’m having. Happens only on the first page load. Once the site’s been cached, it’s ok. |
@migs540 I thought it was Google Analytics, then I disabled it but the issue persisted. I now have re-enabled it. |
@PiotrF Yes. It was behaving strangely for me which is why I ran up a version of https://github.com/gatsbyjs/gatsby/tree/master/examples/using-gatsby-image at trustingcustomers.com Keyframes are CSS. So CSS is being run twice? Or part of the DOM is updating triggering CSS again? Not sure how CSS works at the dom / virtual dom level. Here's the point where the second animation occurs. There's an event load and: |
Well this is bad… it sounds like Gatsby is rendering twice perhaps? What happens if you add a console.log to the render function? Could one of you create a small reproduction site I could look at? E.g. your using-gatsby-image fork @migs540 |
@KyleAMathews I created a new repository (because I couldn't work out how to fork just a subsection of gatsbyjs): https://github.com/migs540/debug-animations-using-gatsby-image That is what is running at http://trustingcustomers.com/ It comes from the original ( https://github.com/gatsbyjs/gatsby/tree/master/examples/using-gatsby-image ) with styled-components added and edits to two files: index.js and blur-up.js - both of these have a one second animation for an enclosing div styled with styled-components. I haven't added a console.log (don't know where) but am wondering if it has anything to do with manipulating the after initial load? But yes, better to follow the logs / load progress and see what is actually happening. |
Awesome! I should have time in the morning to investigate (if you don't solve it of course while I sleep :-)) |
@KyleAMathews we all win when you are awake. In short: animations are executed twice. Once in index.html then a second time in componentindex.js: I added console logging and can see the render is triggered just once in js (in component---src-pages-index-js-2d6cb1471a0df592f43f.js): ...E=(0,T.keyframes)(f),x=t.AboutContents=k.default.div(d,E),A=function(t){function n(){return(0,o.default)(this,n),(0,i.default)(this,t.apply(this,arguments))}return(0,u.default)(n,t),n.prototype.render=function(){return console.log("IndexComponent triggered me during render"),e.createElement...
but well before that the animation is triggered (presumably from index.html:
Video of behaviour (chrome dev tools) at: http://trustingcustomers.com/consolelogging.mp4 Note: console logging is not in place in the repo I mention above - and you need to do a gatsby build to see the behaviour (gatsby develop triggers it just once because of the way it serves files locally). |
Thanks for all your research + reproduction @migs540. Only had a brief moment to look at it so far but this is definitely a hydration issue — if you disable JavaScript then it only animates once. So now to see if the hydration problem is generic and needs fixed in core or if it's triggered by certain behaviors in sites. |
The problem with your reproduction site is you have both gatsby-plugin-glamor and gatsby-plugin-styled-components added to the config. This broke the client side hydration causing a complete re-render. When I moved the styled-components stuff into a css file and removed gatsby-plugin-styled-components, things started working as expected. From 7c26a916063a4d04b856cc76e6a0ac53e7aa3053 Mon Sep 17 00:00:00 2001
From: Kyle Mathews <[email protected]>
Date: Sat, 2 Dec 2017 20:00:42 -0800
Subject: [PATCH] Fix
---
gatsby-config.js | 1 -
package.json | 1 -
src/pages/index.css | 13 +++
src/pages/index.js | 22 +---
yarn.lock | 307 ++++++++++++++++++++++++----------------------------
5 files changed, 159 insertions(+), 185 deletions(-)
create mode 100644 src/pages/index.css
diff --git a/gatsby-config.js b/gatsby-config.js
index 55dfd29..90c227a 100644
--- a/gatsby-config.js
+++ b/gatsby-config.js
@@ -2,7 +2,6 @@ module.exports = {
plugins: [
`gatsby-plugin-glamor`,
`gatsby-plugin-netlify`,
-`gatsby-plugin-styled-components`,
`gatsby-transformer-sharp`,
{
resolve: `gatsby-source-filesystem`,
diff --git a/package.json b/package.json
index 8167420..48dd74b 100644
--- a/package.json
+++ b/package.json
@@ -15,7 +15,6 @@
"gatsby-source-filesystem": "^1.5.1",
"gatsby-transformer-sharp": "^1.6.12",
"numeral": "^2.0.6",
- "sharp": "^0.18.4",
"styled-components": "^2.2.3",
"typeface-oswald": "^0.0.40",
"typeface-pt-sans": "^0.0.40",
diff --git a/src/pages/index.css b/src/pages/index.css
new file mode 100644
index 0000000..90f40cd
--- /dev/null
+++ b/src/pages/index.css
@@ -0,0 +1,13 @@
+@keyframes swingDown {
+ 100% { transform: translateX(0%); }
+}
+
+.about-div {
+ transform: translateX(-100%);
+ -webkit-transform: translateX(-100%);
+ animation: swingDown 1s forwards;
+ animation-fill-mode: forwards;
+ position: relative;
+ z-index: 10;
+ box-shadow: 8px 8px rgba(0, 0, 0, 0.15);
+}
diff --git a/src/pages/index.js b/src/pages/index.js
index be96fba..2fd39d1 100644
--- a/src/pages/index.js
+++ b/src/pages/index.js
@@ -2,30 +2,16 @@ import React from "react"
import Link from "gatsby-link"
import Img from "gatsby-image"
import Navigation from "../components/navigation"
+import "./index.css"
import { rhythm, options } from "../utils/typography"
-import { injectGlobal, css, keyframes } from "styled-components"
-import styled from "styled-components"
-
-const swingDown = keyframes`
- 100% { transform: translateX(0%); }
-`
-
-export const AboutContents = styled.div`
- transform: translateX(-100%);
- -webkit-transform: translateX(-100%);
- animation: ${swingDown} 1s forwards;
- animation-fill-mode: forwards;
- position: relative;
- z-index: 10;
- box-shadow: 8px 8px rgba(0, 0, 0, 0.15);
-`
class IndexComponent extends React.Component {
render() {
+ console.log("rendering")
return (
<div>
- <AboutContents>
+ <div className="about-div">
<Img
css={{ top: 0, left: 0, right: 0, zIndex: -1 }}
style={{ position: `absolute` }}
@@ -128,7 +114,7 @@ class IndexComponent extends React.Component {
</a>
</p>
</div>
- </AboutContents>
+ </div>
</div>
)
} |
OK @KyleAMathews - I suspected it had something to do with how i was using styled-components and can see what you've done here. However, I'd like to use styled-components with gatsby. Is it possible to do the same here and drop the glamor plugin (keeping styled-components)? I tried that a short time ago and it failed (but it was only a quick test). Is it a case of either glamor or styled-components? Or just styled-components? I'm a big fan of @mxstbr 's styled components and would love to be able to use it on gatsby to render once. |
Is that a general gatsby-config.js
|
@KyleAMathews, I have now create a simple site/repo that you can have a look at: https://priceless-minsky-70fda7.netlify.com/ that gets deployed from https://github.com/piotrf/gatsby-test — any help in solving this flickering mystery much is appreciated. |
@KyleAMathews and everyone, resurfacing this as I am having the same issues with my personal site: https://416serg.me/ Plugins I use:
|
I'm still having this issue, too when using styled-components. |
@pie6k are you using gatsby-plugin-styled-components? |
Yes, I think my issue is related to using it. |
Maybe this is a rehydration issue? I took a screen recording of Chrome's animation inspector running on @PiotrF's repro site: https://www.dropbox.com/s/h8nsguy5p8dzonl/issue-3067-animation-flicker.mov?dl=0 It shows the animations running twice. The class names on the animated items change between the first animation and the second animation. In the second animation, hovering the highlighted divs will highlight them in the page. For the first animation that doesn't happen, as the divs no longer exist. Could the styled components plugin be generating different classnames during the SSR phase and the browser phase? This might then cause React to re-render the page using the new class names, which is retriggering the animations? |
Should |
I have the same problem |
@KyleAMathews is there any way to use styled components with the current state of things? |
@markelog Lots of people are using styled-components successfully — what problems are you seeing? |
Exact same issue described in the ticket - page is rerendered and assets are redownloaded :/.
I suppose it’s not that directly noticeable if you don’t have animation, but it’s there
Regards,
Oleg
… On 25 Mar 2018, at 23:10, Kyle Mathews ***@***.***> wrote:
@markelog Lots of people are using styled-components successfully — what problems are you seeing?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
It does sound like several people are having trouble with gatsby-plugin-styled-components — @m-allanson's guess that it has something to do with the babel plugin not being included seems plausible. @markelog would you like to try adding the SC babel plugin to the gatsby plugin to see if that fixes things? You can setup a development environment using the instructions here https://www.gatsbyjs.org/docs/how-to-contribute/ You'd add the SC babel plugin like we do for Glamor
|
Can’t promise I will be productive, since I usually limited with my time. But I will do my best :)
Regards,
Oleg
… On 26 Mar 2018, at 00:31, Kyle Mathews ***@***.***> wrote:
It does sound like several people are having trouble with gatsby-plugin-styled-components — @m-allanson's guess that it has something to do with the babel plugin not being included seems plausible.
@markelog would you like to try adding the SC babel plugin to the gatsby plugin to see if that fixes things?
You can setup a development environment using the instructions here https://www.gatsbyjs.org/docs/how-to-contribute/
You'd add the SC babel plugin like we do for Glamor https://github.com/gatsbyjs/gatsby/blob/958b76de9f779f32406bcc7dffca6e2312155c43/packages/gatsby-plugin-glamor/src/gatsby-node.js#L12
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Actually... lemme just fix this. The plugin is really widely used and it'll only take me a sec to add the babel plugin. Thanks for offering! |
Put up the PR #4722 Once the tests pass & I release it, you'll just need to upgrade to the latest gatsby-plugin-styled-components and install babel-plugin-styled-components into your project. |
Nice! Thank you :)
Regards,
Oleg
… On 27 Mar 2018, at 01:06, Kyle Mathews ***@***.***> wrote:
Put up the PR #4722
Once the tests pass & I release it, you'll just need to upgrade to the latest gatsby-plugin-styled-components and install babel-plugin-styled-components into your project.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Thanks for the effort @KyleAMathews. This did not do the trick for me. Stuff still flickers: https://priceless-minsky-70fda7.netlify.com/ Here’s the source, if anyone wants to help out nailing this down: https://github.com/piotrf/gatsby-test |
Yeah @m-allanson, also installed I've just updated We've also got a few other gatsby plugins installed (ie. gatsby-plugin-offline, gatsby-plugin-manifest, etc). However just done a test-run removing all plugins except |
So there's nothing in the console? |
Would appear so @KyleAMatthews, all I saw were some service worker & A-frame related messages that are present in our other build too.
… On 26 Apr 2018, at 07:45, Kyle Mathews ***@***.***> wrote:
So there's nothing in the console?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I'm also facing the same issue. |
@PiotrF I tried looking into this again, using the repo you posted earlier. Running Or if anyone has source for a simple demo site that replicates this problem and uses |
@m-allanson the repo for the project I'm linking to is currently over on GitLab - hope that helps 🙂 (It's still in baby steps, recently born from the starter - as you'll be able to tell from the package.json 🙈) |
Thanks @breadadams, that does help! I've created a test version of your site - stripping out the bits that aren't related to this issue. Repo: https://github.com/m-allanson/test-gatsby-animation This looks like the server generated classnames are different from the browser rendered classnames. You can see this by running the site with or without JS enabled. With JS - notice animation being retriggered just after the page loads: Without JS - the animation runs smoothly: The With JS demo it looks like the page loads with the server generated classnames, then they get changed by the client, causing the animations to restart. In the Without JS demo, only the server generated classnames are being used and the animation just runs once. If anyone can work out why there's a difference between the server and client side classnames, that should hopefully solve this issue. |
Awesome @m-allanson!! Looking thru the src for |
If you wanted to try some debugging, you could copy the plugin source as a local plugin and play around with it. For a more in-depth setup checkout the instructions for using gatsby-dev. |
Thanks, will do. Here's a possible related issue I've come across: vercel/next.js#3706 |
@breadadams the reason it's returned twice is we added support for the babel plugin recently and to avoid having to do a major release due to a breaking change, we check if the plugin is installed before adding it. If you haven't added the babel plugin, that could be the problem. |
Installing babel-plugin-styled-components did it for me! Thanks! |
Yeah @KyleAMathews I get that, but both the returns I mention are within the We have Did you literally just install the babel plugin @JoaoTMDias? Or also include it in your |
Hi everyone, just wanted to confirm that I had the same flickering issue with styled-components and it was fixed after updating I really love Gatsby, thanks for making it awesome! |
Just in case anyone else comes across this thread, like I did, from getting the errors:
or
...you might simply need to add an import for
This is probably completely obvious to developers used to React, but it took me way too long to figure out. 😄I hope this doesn't feel like clutter in the overall thread; I just don't really know where else makes sense for this, as Google brought me to this thread and I tried to other solutions in vain (because my problem was simpler). Hope this helps someone! |
I'm still having this problem after trying local .babelrc.js. Anyone solved it yet? Reproduce: |
I'm having the same issue at https://mrintoul.com/, although it doesn't happen when the page is loaded — it happens every time I hover over a link (perhaps every time something is eager loaded?). I believe I've tried all the recommendations in this thread and a few others, but no luck. It only happens after build, not while using I've made the repository public for now, if anyone has a chance to verify it's not my implementation error. It's deployed on Netlify. |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! Thanks for being a part of the Gatsby community! 💪💜 |
Will try to get our site's dependencies updated to latest versions and give this another test... Please don't close yet 🙏 |
@breadadams any luck with the latest versions? |
Hey all, i'm going to close this one as it's pretty old. Please create a new ticket with new information and reproduction if possible. Thanks for using Gatsby and your understanding! |
I’m having a hard time getting around an issue that I think has to do with
domready
. Each time I load my site (https://piotrf.pl) the plain keyframe CSS animations are being triggered twice, which causes an awkward flickering: https://s3-us-west-2.amazonaws.com/dropbox.piotrf.pl/Untitled.movNote how this flickering occurs only on server, not on hotloaded localhost. Here’s why I think
domready
might be involved:Has anyone encountered a similar issue?
The text was updated successfully, but these errors were encountered: