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

[JIMT]CT-492] editor-overwrites - fixes editor from overwriting itself #57928

Merged
merged 4 commits into from Apr 12, 2024

Conversation

thomasoniii
Copy link
Contributor

If you changed levels, your editor would overwrite the contents of the proper file with the default values provided in Weblab2View.tsx.

There were two issues going on -

  • CDOIDE was setting the shouldNotifyProjectUpdate flag too late in the process, which would noisily cause an update of the last project value before replaceProject was called for the new one. This would end de-syncing and overwriting with the prior value of the project. Fix here was to swap the effect order and bubble up where the shouldNotifyProjectUpdate flag was set.
  • saveProject would fire a save even if the project itself was the same. This could cause de-sync issues when switching rapidly between levels and could end up overwriting or even swapping content. Fix here was to only save if the value actually changed.

Links

Comment on lines +66 to +70
useEffect(() => {
shouldNotifyProjectUpdate.current = false;
projectUtilities.replaceProject(project);
}, [project, projectUtilities]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I know that effects shouldn't depend upon each other, but because we're using a ref here it kinda has to until this is swapped out with something a little less clunky.

@@ -83,7 +83,7 @@ const defaultProject: ProjectType = {
<link rel="stylesheet" href="styles.css"/>
<body>
Content goes here!
<div class="foo">Foo class!</div>
<div class="foo">[DEFAULT] Foo class!</div>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to hopefully help us see when we're loading in default data. I'd encourage everyone to change your data when you navigate in and save, so that if this ever shows up it's more clear.

if (Lab2Registry.getInstance().getProjectManager()) {
if (
Lab2Registry.getInstance().getProjectManager() &&
newProject !== currentProject
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we blindly save even if there's no change, it can overwrite if you navigate too fast.

This is kinda a hack solution - it'd be better for CDOIDE not to fire off the additional noisy note, and it'd also be better if the project manager's save could somehow take into account if nothing's changing (but that's probably asking too much since it doesn't maintain state otherwise).

Copy link
Contributor

Choose a reason for hiding this comment

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

The project manager actually does check if nothing has changed, and does not save in that case (link). Is the problem here that the channel id has changed but we are sending a late update with the code from the previous channel id?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this get called if you navigate between levels? Shouldn't we only call setProject when the project has been changed, not when it is initially loaded?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem was that the setProject function wasn't memoized.

In turn, when you navigated it'd create a new setProject function which'd fall into the IDE and trigger the effect to claim that the project had changed, even though it hadn't in this case. With a memoized function, it behaves as expected.

Further, though, this is a bigger issue beyond this code - because the project manager's save method only takes data to save and not the channelID to save it to (I think I'm using the right terms), it's susceptible to this type of issue -

basically, if the user navigates old data from the prior level may still be loaded into components. If something is triggered which would cause a save, it might push forward the stale data to the project manager, which would then overwrite the new channelID with the prior channel's data. It's assuming that all data that currently exists on the page is new, but if it hasn't been refreshed yet it's stale, and if that stale data triggers a save, it'd overwrite.

As it did in this case since the function wasn't memoized. This should be flagged as a future fix to circle back to.

Copy link
Contributor

Choose a reason for hiding this comment

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

I made a follow up task to look into the caching idea I came up with: https://codedotorg.atlassian.net/browse/CT-500

@thomasoniii thomasoniii requested a review from a team April 10, 2024 17:45
@thomasoniii thomasoniii merged commit 91f3088 into staging Apr 12, 2024
2 checks passed
@thomasoniii thomasoniii deleted the jimt/CT-492/editor-overwrites branch April 12, 2024 16:40
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.

None yet

2 participants