Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
✨ Initial amp-timeago Bento component #26507
✨ Initial amp-timeago Bento component #26507
Changes from 1 commit
f2c903d
4271a9c
7c52654
f979136
0ec8325
f357dd4
1d4ed68
ec88e89
170c55c
178d13d
7546ac2
ef07436
3ef8b19
08d869d
b02dd4b
7d9c279
c4890a1
45d6581
b8c30c2
b7b61f6
a6beb2d
5755f4e
748f2f9
630ceb1
78df30a
4c4464a
7eb6bfd
9f14bfc
225d596
ef30173
ea197ca
e018573
1453b39
69242f2
96fba1f
b112d05
395e1ae
6b78d30
d7cd8bf
fb36fd5
f790b35
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the timestamp on each render. And per spec it should only do so when the element returns back to the viewport, right? Why not just do it in the
if (isIntersecting) {}
and store the value in the state instead ofisIntersecting
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the impression that this approach will cost us rendering a fresh timestamp on
prop
mutation from amp-bind. Specifically this is the case that's important to support:i.e. the following does nothing on prop mutation.
We could update the
timestamp
on every render to handle prop mutation, but that both doesn't differentiate between the attempt to render on exit viewport and can also be consolidated into the approach we have now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So,
I think you can follow Dima's suggestion, but then also have a clause like this to update on prop change:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See reactjs/rfcs#107 (comment), and reactjs/rfcs#107 (comment). We should not do that.
We have two cases for intersecting rerendering now:
false
->true
true
->false
If we want to make it so that we only rerender when
false
->true
, we need to introduce a high order state helper. I had proposed something like:This will cause a rerender only when
inIntersecting
goes fromfalse
->true
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But, I think the code was fine as is, it doesn't matter too much if timeago renders when exiting viewport.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rerunning effect on prop change is very common and no problem with it that I can think of. The "this pattern is shady" in the links, I believe, is with passing arrays around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the initial problem wasn't with the "renders when exiting viewport", but with the content changing on every external rerender with state/props being invariant.