Appearance
Script Tag: Upgrading from v3 to v4
This is the upgrade path for pages that embed the editor with the loader <script> tag and TopolPlugin.init(). If you install the editor from npm, follow NPM Packages: Upgrading to v1 instead. For what's new in v4 and how to tell which path is yours, see Migrating to Email Editor v4.
In v4 you create an editor instance instead of calling a global TopolPlugin, callbacks receive one object, and a few options were renamed. Your templates keep working. v4 opens the same template JSON as v3.
Most integrations need these steps:
- Switch the loader URL.
- Create the editor with
TopolEmailEditor()andrender(). - Call methods on the editor instance.
- Convert callbacks to the object payloads.
- Rename a few options.
- Update your backend and security policy, if they reference v3.
Let an AI agent do the upgrade
TOPOL-io/skills has a topol-editors-upgrade-email-v4 skill that walks a coding agent through this guide. It installs as a Claude Code plugin (/plugin marketplace add TOPOL-io/skills) or into any agent with npx skills@latest add TOPOL-io/skills.
Step 1: Switch the loader URL
html
<!-- Before -->
<script src="https://v3.email-assets.topol.io/loader/build.js"></script>
<!-- After -->
<script src="https://v4.email-assets.topol.io/loader/build.js"></script>Load the script once per page. Loading it a second time throws Can not register multiple components with the same tag. One loaded script can create several editors.
Step 2: Create the editor instance
The loader now defines a global TopolEmailEditor factory instead of TopolPlugin. Options go under config, callbacks sit next to it, and render() mounts the editor into your container.
js
const TOPOL_OPTIONS = {
id: "#app",
authorize: {
apiKey: "YOUR_API_KEY",
entityId: "user-123",
},
callbacks: {
onSave(json, html) {
saveTemplate(json, html);
},
onError(type, message) {
console.error(type, message);
},
},
};
TopolPlugin.init(TOPOL_OPTIONS);
TopolPlugin.load(template);js
const editor = TopolEmailEditor({
config: {
authorize: {
apiKey: "YOUR_API_KEY",
entityId: "user-123",
},
},
onSave({ json, html }) {
return saveTemplate(json, html);
},
onEditorError({ source, message }) {
console.error(source, message);
},
});
editor.render("#app");
editor.load(template);| Change | v3 | v4 | What to do |
|---|---|---|---|
| Global | TopolPlugin.init(options) | TopolEmailEditor({ config, ...callbacks }) returns an editor instance | Keep the instance in a variable |
| Container | id option | editor.render("#app") or editor.render(element) | Remove id; the container still needs an explicit width and height |
| Options | Top level of TOPOL_OPTIONS | Inside config | Move them under config; config is required |
| Callbacks | Inside callbacks | Top-level properties next to config | Move them out; callbacks left inside config are ignored |
entityId | Any string or number | Letters, numbers, _ and -, or a non-negative integer | Map other IDs (emails, dotted IDs) to a URL-safe value, or init fails with onEditorError |
Calls made right after render(), such as editor.load(template), wait until the editor is ready. If authentication or initialization fails, you get onEditorError and those calls never finish. Fix the cause, call editor.destroy(), and create a new instance.
Recommended: nonce authentication
authorize.apiKey keeps working on its own in v4, but the setup we recommend is nonce authentication. Add a getNonce callback next to config: the editor then runs on short-lived nonces that your backend signs for each signed-in user with the Secret key. You can add it now or after the upgrade. See Nonce Authentication.
Step 3: Call methods on the instance
Every method now lives on the editor instance and returns a Promise.
| v3 | v4 |
|---|---|
TopolPlugin.load(json) | editor.load(json); resolves once the template is applied |
TopolPlugin.save() / TopolPlugin.save("en") | editor.save() / editor.save({ langCode: "en" }) |
TopolPlugin.destroy() | editor.destroy(); editor.close() is an alias |
TopolPlugin.setSavedBlocks(list) | editor.setSavedSections(list) |
TopolPlugin.getMutations() (result via onGetMutations) | editor.getMutations() resolves to [{ code, primary }] and still fires onGetMutations |
TopolPlugin.toggleBlocksAndStructuresVisibility() | editor.toggleHiddenElementsVisibility() |
TopolPlugin.toggleControlPanel() | editor.toggleSelectionPanel() |
Any other TopolPlugin.method() | editor.method(), same name and arguments |
The v3 method names are gone: calling editor.setSavedBlocks(), editor.toggleBlocksAndStructuresVisibility() or editor.toggleControlPanel() throws "not a function".
editor.save() rejects with err.code === "SAVE_IN_PROGRESS" if another save is still running. Errors during saving are reported through onEditorError with source: "save".
Step 4: Convert callbacks to object payloads
Every callback now receives either nothing or one object. Eight callbacks were renamed.
| v3 | v4 |
|---|---|
onSave(json, html, mutations, syncedSections) | onSave({ json, html, mutations, syncedSections }) |
onSaveAndClose(json, html, mutations, syncedSections) | onSaveAndClose({ json, html, mutations, syncedSections }) |
onTestSend(email, json, html) | onTestSend({ email, json, html }) |
onBannerClick(json, html) | onBannerClick({ json, html }) |
onImageDelete(items) | onImageDelete({ items }) |
onUndoChange(count) / onRedoChange(count) | onUndoChange({ count }) / onRedoChange({ count }) |
onPreview(html) | onPreview({ html }) |
onAlert(notification) | onAlert({ notification }) |
onEdittedWithoutSaveChanged(hasUnsavedChanges) | onUnsavedChangesChange({ hasUnsavedChanges }) |
onBlocksAndStructuresVisibilityChange(visible) | onHiddenElementsVisibilityChange({ visible }) |
onOpenCustomBlockDialog(block) | onOpenCustomBlockDialog({ block }) |
onTemplateRename(title) | onTemplateRename({ name }) |
updateTestingEmailAddresses(emails) | onTestingEmailsChange({ emails }) |
onLanguageCreated(lang, mutations) | onLanguageCreated({ code, mutations }); same for onLanguageDeleted and onPrimaryLanguageChanged |
onLanguageSelected(lang) | onLanguageSelected({ code }) |
onGetMutations(mutations) | onGetMutations({ mutations }) |
onError(type, message, responseBody) | onEditorError({ source, message, detail }) |
onClose() | onEditorClose() |
onBlockSave(block) | onSavedSectionSave({ section }) |
onBlockRemove(blockId) | onSavedSectionRemove({ id }) |
onBlockEdit(blockId) | onSavedSectionEdit({ id }) |
onInit(), onLoaded(), onOpenFileManager(), onTemplateUpdated(), onPreviewClose() | Unchanged |
Language mutations in mutations change from { lang, primary } to { code, primary }. The error type templateLoad is now source: "load".
Old callback names fail silently
A callback under its v3 name is never called, and nothing warns you. onClose and onError are worse: in v4 they belong to the iframe library and fire on its own events, not the editor's. Rename them to onEditorClose and onEditorError.
Step 5: Rename options
Unknown options are ignored, so an option left under its old name stops working without an error.
| v3 | v4 | What to do |
|---|---|---|
authorize.userId | authorize.entityId | Rename |
savedBlocks | savedSections | Rename; the item shape is the same |
premadeBlocks | premadeSections | Rename; the value keeps the same shape |
premadeBlocksNoOverwrite | Removed | Drop it. To keep Topol's default groups next to yours, use premadeSections: { blocks, override: false } |
hideControlPanel | hideSelectionPanel | Rename |
showControlPanelExpand | hideSelectionPanelExpand | Rename and invert the value: showControlPanelExpand: false becomes hideSelectionPanelExpand: true |
productMergetagTags | productMergeTags | Rename |
dynamicMergetags on an API block | dynamicMergeTags | Rename |
topBarOptions (buttons to show) | hideTopbarControls (buttons to hide) | Invert the list |
defaultTemplateSettings.langs: [{ key, primary }] | defaultTemplateSettings.langs: [{ code, primary }] | Rename key to code |
defaultTemplateSettings.blockBackgroundColor | defaultTemplateSettings.sectionBackgroundColor | Rename |
defaultTemplateSettings["structure-margin"] | defaultTemplateSettings.sectionPadding | Rename |
defaultTemplateSettings["line-height"] | defaultTemplateSettings.lineHeight | Rename the top-level key; "line-height" inside the block-level defaults (text, button, …) is an MJML attribute and stays |
defaultTemplateSettings["stack-columns"] | defaultTemplateSettings.stackColumns | Rename |
api.AUTOSAVE, api.GET_AUTOSAVE | Removed | Serve autosaves from api.AUTOSAVES; see Step 6 |
api.SAVE, api.LOAD | Removed | Persist in onSave; load with editor.load() |
api.PREMADE_TEMPLATES_KEYWORDS | api.PREMADE_TEMPLATE_KEYWORDS | Rename |
api.IMAGE_EDITOR_UPLOAD | Removed | Images saved from the Image Editor upload through api.IMAGE_UPLOAD; see Self-hosted Storage |
googleApiKey | Removed | Drop it; the Image Editor takes its fonts from customFonts |
textOverride keys saved_blocks*, premade_blocks, save_as_block, synced_rows, *_synced_row* | saved_sections*, premade_sections, save_as_section, synced_sections, *_synced_section* | Rename the keys you override |
Misspelled textOverride keys | Corrected spelling | Rename the ones you override; see the list below |
Renamed textOverride keys
v4 fixes the spelling of these custom label paths. An override left under the old path is ignored and the label falls back to the editor's default text.
| v3 | v4 |
|---|---|
layout.chatAI.grammer | layout.chatAI.grammar |
layout.chatAI.questions.personalizate | layout.chatAI.questions.personalize |
forms.GPA.not_quaranted | forms.GPA.not_guaranteed |
forms.settings_line_heigh_precise | forms.settings_line_height_precise |
forms.settings_line_heigh_predefined | forms.settings_line_height_predefined |
forms.settings_bgc | forms.settings_background_color |
forms.stuck | forms.stack_columns |
forms.do_not_stuck | forms.do_not_stack_columns |
errors.invalid_HTML_row | errors.invalid_html_section |
errors.fix_HTML | errors.fix_html |
product.recommeneded | product.recommended |
Defaults that changed
These features are now on by default. Set the option explicitly to keep the v3 behaviour.
| Option | v3 default | v4 default |
|---|---|---|
smartMergeTags.enabled | false | true |
mobileFirstEnabled | false | true |
premadeTemplates | false | true |
| Control panel toggle | Hidden (showControlPanelExpand: false) | Shown (hideSelectionPanelExpand: false) |
The control panel also starts hidden when the editor is narrower than 1024 px.
Step 6: Update your backend and security policy
If you host api.* endpoints, they need the v4 CORS origin and the merged autosave endpoint. If your page sets a Content Security Policy, it needs the v4 loader domain. Both changes are the same for NPM integrations, so they're described once in Backend and security policy.
Behaviour changes to check
- Saving waits for your backend. If
onSaveoronSaveAndClosereturns a Promise, the editor keeps its saving indicator until it settles. A rejected Promise shows a saving error. After 30 seconds the editor stops waiting and shows a notice that the save was not confirmed. - Unsaved changes are marked as saved only after your
onSavefinishes, and only if the template didn't change in the meantime. - Save & Close without
onSaveAndClosenow callsonSaveand then closes the editor. In v3 nothing happened. - The window bar's close button without
onEditorClosenow closes the editor by itself. - Failed authentication reports
onEditorErrorwithsource: "authorize", thensource: "init". Create a new instance after fixing the credentials.
INFO
Running into trouble while upgrading? Contact our support team here and we'll help you get it working.
