Skip to content

Conversation

@hejtful
Copy link
Contributor

@hejtful hejtful commented Nov 6, 2024

Resolves #4241

Note: First commit is only cleaning up, second commit fixes the bug.

This took way longer to figure out than I'd like to admit 😬
The editor emits onChange events when actions are committed to history, not when actions are resolved.
For most changes, this doesn't matter, as we first resolve actions, then commit them to history.
There are, however, these "temporary" actions, used in asyncScalar. One use-case of asyncScalar is uploading an image, where we had the bug. And in these "temporary" actions, we were first committing actions to history, then resolving them, which led the editor to emit onChange before its state was updated.

I snooped around the code to see if I could find any reason for this difference between regular and "temporary" actions, and I couldn't find any. I also tested the editor, and everything seems to work fine, but it would be great if you could test a bit as well.

Explanation for "temporary" actions (asyncScalar): I believe these were initially created to support loading states of async actions. So once a user uploads an image, a temporary action would show a loading screen, and then a normal action would show the uploaded image and the temporary action would be removed from history. That would make sure that undo/redo works as expected -- never showing the loading screen. I couldn't figure out how to use this, though. Either the feature was never finished, or we broke it unknowingly.

@elbotho This also fixes the ___editor_preview -- the right side will now show the image as soon as it's uploaded.

@vercel
Copy link

vercel bot commented Nov 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
frontend ✅ Ready (Inspect) Visit Preview Nov 6, 2024 2:02pm

@hejtful hejtful changed the title Fix/image src state fix(editor): commit temporary commit actions to history only after resolving them Nov 6, 2024
@hejtful hejtful changed the title fix(editor): commit temporary commit actions to history only after resolving them fix(editor): commit temporary actions to history only after resolving them Nov 6, 2024
@hejtful hejtful marked this pull request as draft November 6, 2024 14:05
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2024

📦 Next.js Bundle Analysis for @serlo/frontend

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 104.42 KB (🟡 +1 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Seven Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/___editor_preview 530.25 KB (-5 B) 634.67 KB
/entity/create/[type]/[taxonomyId] 550.34 KB (-5 B) 654.75 KB
/entity/repository/add-revision/[...id] 550.07 KB (-5 B) 654.49 KB
/page/create 550.06 KB (-5 B) 654.48 KB
/taxonomy/term/create/[parent_id]/[id] 549.81 KB (-5 B) 654.23 KB
/taxonomy/term/update/[id] 549.76 KB (-5 B) 654.17 KB
/user/settings 551.75 KB (-5 B) 656.17 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

@hejtful hejtful marked this pull request as ready for review November 6, 2024 14:06
Copy link
Member

@elbotho elbotho left a comment

Choose a reason for hiding this comment

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

👍 thank you for the deep dive!
Not sure I would have figured that one out.

Copy link
Member

@LarsTheGlidingSquirrel LarsTheGlidingSquirrel left a comment

Choose a reason for hiding this comment

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

I don't know enough about the relevant code but I tested the editor and performed a lot of undo/redo and found no issue.
Thank you for looking into this and finding a solution!

@hejtful hejtful merged commit 0f8b25d into staging Nov 11, 2024
@hejtful hejtful deleted the fix/image-src-state branch November 11, 2024 11:54
@github-actions github-actions bot mentioned this pull request Nov 11, 2024
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.

editor(plugin-image): uploaded image not in state until next change

4 participants