Skip to content

[Embeddable Rebuild] Fix stuck unsaved changes#190165

Merged
Heenawter merged 8 commits intoelastic:mainfrom
Heenawter:embeddableRebuild-fix-unsaved-changes_2024-08-08
Aug 12, 2024
Merged

[Embeddable Rebuild] Fix stuck unsaved changes#190165
Heenawter merged 8 commits intoelastic:mainfrom
Heenawter:embeddableRebuild-fix-unsaved-changes_2024-08-08

Conversation

@Heenawter
Copy link
Copy Markdown
Contributor

@Heenawter Heenawter commented Aug 8, 2024

Closes #190066

Summary

In #189128 (comment), I suggested adding a skip to the comparators subscription in order to prevent unsavedChanges from emitting twice - however, while I was on the right track with this suggestion, I didn't look closely enough at how this worked. Essentially, this is how it worked without the skip when creating a brand new React embeddable:

  1. We initialize unsavedChanges by calling runComparators to get its initial value - since it is a new embeddable and therefore does not have unsaved state, it returns the entire state per the early return in runComparators
  2. The comparator subjects all emit and, after the debounce, unsavedChanges gets set again by calling runComparators - similarly, it returns the entire state due to the early return.
  3. Unsaved changes emits twice unnecessarily - once at initialization, once after a debounce 🔥

By adding the skip where I suggested, this is what happened:

  1. We initialize unsavedChanges by calling runComparators to get its initial value - it returns the entire state due to the early return.
  2. We ignore the first emit of every comparator due to the skip - this is good, because unsaved changes emits only once!
  3. But, when we go to save the dashboard, the placement of the skip made it so that the subscription did not fire when lastSavedState emits - it is waiting for the comparators to emit again before firing! So, the unsaved changes remains unnecessarily 🔥

Essentially, we want to skip the first emit of the whole comparator + lastSavedState observable that results from the pipe - not just the comparators. Otherwise, we don't get to the combineLatestWith until after the comparators emit a second time, which means we don't respond whenlastSavedState emits after a React embeddable panel is freshly added. By rearranging the order of operations in the pipe, we achieve the desired behaviour.

To test the above, move the skip to before the lastSavedState emit. Add a React embeddable panel, and try to save - unsaved changes will be stuck. On a fresh dashboard, add a React embeddable panel again, edit that React embeddable to trigger a comparator emit, then save - unsaved changes is cleared!

Checklist

For maintainers

@Heenawter Heenawter added release_note:fix Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas t// loe:small Small Level of Effort impact:critical This issue should be addressed immediately due to a critical level of impact on the product. project:embeddableRebuild labels Aug 8, 2024
@Heenawter Heenawter self-assigned this Aug 8, 2024
@Heenawter
Copy link
Copy Markdown
Contributor Author

/ci

@Heenawter Heenawter force-pushed the embeddableRebuild-fix-unsaved-changes_2024-08-08 branch 2 times, most recently from 7dac049 to ebc3b4d Compare August 8, 2024 17:35
@Heenawter
Copy link
Copy Markdown
Contributor Author

/ci

@Heenawter Heenawter force-pushed the embeddableRebuild-fix-unsaved-changes_2024-08-08 branch from f6bc372 to bc10479 Compare August 8, 2024 23:15
@Heenawter Heenawter force-pushed the embeddableRebuild-fix-unsaved-changes_2024-08-08 branch from bc10479 to e20c427 Compare August 8, 2024 23:16
@Heenawter
Copy link
Copy Markdown
Contributor Author

/ci

@Heenawter Heenawter marked this pull request as ready for review August 9, 2024 01:04
@Heenawter Heenawter requested a review from a team as a code owner August 9, 2024 01:04
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-presentation (Team:Presentation)

@nreese nreese self-requested a review August 9, 2024 14:19
@Heenawter Heenawter force-pushed the embeddableRebuild-fix-unsaved-changes_2024-08-08 branch from 2cab20a to fabd6be Compare August 12, 2024 14:18
Copy link
Copy Markdown
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

LGTM
code review only

@Heenawter Heenawter enabled auto-merge (squash) August 12, 2024 15:03
@kibana-ci
Copy link
Copy Markdown

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
aiops 564.1KB 564.1KB -36.0B
controls 379.0KB 379.0KB -72.0B
dataVisualizer 799.6KB 799.6KB -18.0B
imageEmbeddable 68.9KB 68.9KB -18.0B
ml 4.6MB 4.6MB -72.0B
total -216.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
embeddable 71.2KB 71.2KB -18.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @Heenawter

@Heenawter Heenawter merged commit 71b90a1 into elastic:main Aug 12, 2024
@kibanamachine kibanamachine added v8.16.0 backport:skip This PR does not require backporting labels Aug 12, 2024
@Heenawter Heenawter deleted the embeddableRebuild-fix-unsaved-changes_2024-08-08 branch August 12, 2024 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting impact:critical This issue should be addressed immediately due to a critical level of impact on the product. loe:small Small Level of Effort project:embeddableRebuild release_note:fix Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas t// v8.16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Embeddable Rebuild] Unsaved changes stuck on Dashboard after adding a React embeddable

5 participants