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

refactor: adjust Frontend to new Editor storage format #4465

Draft
wants to merge 14 commits into
base: staging
Choose a base branch
from

Conversation

hejtful
Copy link
Contributor

@hejtful hejtful commented Feb 7, 2025

Linear: EDTR-98
API (db-migrations) PR: serlo/api.serlo.org#1865
Infra PR: serlo/infra#120

Should only be merged once the DB migration has been run on staging.

Copy link

vercel bot commented Feb 7, 2025

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

Name Status Preview Updated (UTC)
frontend ✅ Ready (Inspect) Visit Preview Feb 11, 2025 2:17pm

Copy link
Contributor

github-actions bot commented Feb 7, 2025

📦 Next.js Bundle Analysis for @serlo/frontend

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

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 105.37 KB (-3 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 201.98 KB (🟡 +7 B) 307.35 KB
/entity/create/[type]/[taxonomyId] 223.67 KB (🟡 +155 B) 329.04 KB
/entity/repository/add-revision/[...id] 223.31 KB (🟡 +130 B) 328.68 KB
/page/create 223.34 KB (🟡 +156 B) 328.71 KB
/taxonomy/term/create/[parent_id]/[id] 223.04 KB (🟡 +158 B) 328.41 KB
/taxonomy/term/update/[id] 222.94 KB (🟡 +130 B) 328.31 KB
/user/settings 225.1 KB (🟡 +130 B) 330.47 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 February 10, 2025 13:26
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.

There are some parts that I don't understand, but to me it looks fine. Let me know if I should look into something specific in more detail.

})
}

return { editorMetadata, templateContent }

Choose a reason for hiding this comment

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

Why is there template in the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it's representing the content of TemplatePluginType. Would templatePluginContent be more understandable?

Choose a reason for hiding this comment

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

Ah, I see. How about just content? Or is this function only for TemplatePluginType?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or is this function only for TemplatePluginType?

Yes. So the editor metadata will be in its content property. But the editor's migrate function isn't expecting that. More detail here.

Comment on lines +48 to +51
...createEmptyDocument('serlo-org'),
document: {
plugin: AllowedPlugins[entityType],
},

Choose a reason for hiding this comment

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

Maybe createEmptyDocument could generate different initial editor states in the future. Example: createEmptyDocument(editorVariant: 'serlo-org', type: 'article')

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 you don't mind, could you please explain the benefits of that in more detail? Is it to avoid this destructuring approach, or are there other benefits?

Choose a reason for hiding this comment

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

When I created this function in the past there was only one root plugin type-generic-content so it made sense to hard code it. Now, there are different types. I think I would slightly prefer having all that logic in function createEmptyDocument. But the way it is now is also fine for me. ☺️

Copy link
Contributor Author

@hejtful hejtful Feb 13, 2025

Choose a reason for hiding this comment

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

Fair point! And it should stay like that, actually. I only exported the createEmptyDocument function through the package as a special case for Serlo (which is also documented by comments in the package index file, and also why it's not mentioned in the README). So it's a temporary hacky solution, and I wouldn't change the original function for it.

It's definitely not great, but I decided that these refactorings need to go step by step, if I tried to make everything perfect on the first go, I'd get lost in it 😁

@hejtful hejtful marked this pull request as draft February 11, 2025 15:37
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