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

Remove Gdoc Preview autoupdating, fix lightning publishing #2766

Merged
merged 4 commits into from
Oct 24, 2023

Conversation

ikesau
Copy link
Member

@ikesau ikesau commented Oct 13, 2023

Autoupdating was causing lots of headaches when multiple clients were previewing the same document. The effort in fixing that class of issue seems to outweigh the marginal benefit of autoupdating, so I'm removing the autoupdating functionality altogether.

I also noticed that lightning updates hadn't been working properly for ages, so I've updated that code to fix the thing that was breaking it (Date comparisons) and made the declaration of light props more explicit and tied to our type validation so that it'll be harder to miss in the future.

@ikesau ikesau requested a review from mlbrgl October 13, 2023 14:52
@ikesau ikesau self-assigned this Oct 13, 2023
Comment on lines 101 to 108
const prevOmitted = omit(
{ ...prevGdoc, tags: nextGdoc.tags?.map((tag) => JSON.stringify(tag)) },
keysToOmit
)
const nextOmitted = omit(
{ ...nextGdoc, tags: prevGdoc.tags?.map((tag) => JSON.stringify(tag)) },
keysToOmit
)
Copy link
Member

Choose a reason for hiding this comment

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

prevOmitted should use prevGdoc.tags (and vice-versa for nextOmitted)

This swap ends up correcting another swap in another part of the codebase, so this is a case of (-) x (-) = (+), but we should still address the inital swap, as it creates other issues.

Here is the scenario that leads to it:

  1. load preview
  2. update gdoc body
  3. refresh preview ("⚡️ Republishing" button appears)
  4. change tags
  5. hit "⚡️ Republishing"

The first surface issue is that a standard publishing triggered. The front-end doesn't know of the change of tags, and still sees this change as a lightning update. This leads to a discrepancy between the visual promise of a ⚡️ update and the effective non-⚡️ update that follows.

The second issue is that tag changes are not persisted if they happen during a preview session. Going back to the previous timeline:

  1. load preview -> e.g. loads tags A and B
  2. update gdoc body
  3. refresh preview ("⚡️ Republishing" button appears)
  4. change tags -> e.g. removes tag B.
  5. hit "⚡️ Republishing"

The change carried out in 4 has not been propagated to the front-end, so the call to apiRouter.put("/gdocs/:id") is made with a mix of nextGdoc's latest properties and the tags that were set on page load. Upon hitting "⚡️ Republishing", the previous set of tags (A and B) is then reapplied. Meanwhile, when prevGdoc is set in that same API call, it is set to the version currently in the DB (conceptually, nextGdoc's tags), hence the swap mentioned earlier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch! Those variables being swapped was just a goof, definitely not intentional. But I'm glad it prompted you pointing out this potential footgun in either case.

I've updated the GdocsStore.update method from the preview page to omit the tags property in the JSON it posts. This means that the tags in the DB won't get changed in any way from publishing a gdoc.

I think this means that technically we should trigger a bake whenever a Gdoc's tags are updated, but we don't do that for charts either, and I think we could try it out this way first (with manual+incidental bake triggers) and see if that works well enough.

Copy link
Member

Choose a reason for hiding this comment

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

yes, I agree.

Tested and both issues are gone, nice!

adminSiteClient/GdocsPreviewPage.tsx Outdated Show resolved Hide resolved
Copy link
Member

@mlbrgl mlbrgl left a comment

Choose a reason for hiding this comment

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

Nice refactoring on the lightning update! It is much more future-proof now that is tied to a type 👍

@ikesau ikesau requested a review from mlbrgl October 23, 2023 23:45
@ikesau ikesau merged commit 847e883 into master Oct 24, 2023
16 checks passed
@ikesau ikesau deleted the fix-unpublishing branch October 24, 2023 20:49
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.

2 participants