Skip to content
Open in

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:

  1. Switch the loader URL.
  2. Create the editor with TopolEmailEditor() and render().
  3. Call methods on the editor instance.
  4. Convert callbacks to the object payloads.
  5. Rename a few options.
  6. 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);
Changev3v4What to do
GlobalTopolPlugin.init(options)TopolEmailEditor({ config, ...callbacks }) returns an editor instanceKeep the instance in a variable
Containerid optioneditor.render("#app") or editor.render(element)Remove id; the container still needs an explicit width and height
OptionsTop level of TOPOL_OPTIONSInside configMove them under config; config is required
CallbacksInside callbacksTop-level properties next to configMove them out; callbacks left inside config are ignored
entityIdAny string or numberLetters, numbers, _ and -, or a non-negative integerMap 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.

v3v4
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.

v3v4
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.

v3v4What to do
authorize.userIdauthorize.entityIdRename
savedBlockssavedSectionsRename; the item shape is the same
premadeBlockspremadeSectionsRename; the value keeps the same shape
premadeBlocksNoOverwriteRemovedDrop it. To keep Topol's default groups next to yours, use premadeSections: { blocks, override: false }
hideControlPanelhideSelectionPanelRename
showControlPanelExpandhideSelectionPanelExpandRename and invert the value: showControlPanelExpand: false becomes hideSelectionPanelExpand: true
productMergetagTagsproductMergeTagsRename
dynamicMergetags on an API blockdynamicMergeTagsRename
topBarOptions (buttons to show)hideTopbarControls (buttons to hide)Invert the list
defaultTemplateSettings.langs: [{ key, primary }]defaultTemplateSettings.langs: [{ code, primary }]Rename key to code
defaultTemplateSettings.blockBackgroundColordefaultTemplateSettings.sectionBackgroundColorRename
defaultTemplateSettings["structure-margin"]defaultTemplateSettings.sectionPaddingRename
defaultTemplateSettings["line-height"]defaultTemplateSettings.lineHeightRename the top-level key; "line-height" inside the block-level defaults (text, button, …) is an MJML attribute and stays
defaultTemplateSettings["stack-columns"]defaultTemplateSettings.stackColumnsRename
api.AUTOSAVE, api.GET_AUTOSAVERemovedServe autosaves from api.AUTOSAVES; see Step 6
api.SAVE, api.LOADRemovedPersist in onSave; load with editor.load()
api.PREMADE_TEMPLATES_KEYWORDSapi.PREMADE_TEMPLATE_KEYWORDSRename
api.IMAGE_EDITOR_UPLOADRemovedImages saved from the Image Editor upload through api.IMAGE_UPLOAD; see Self-hosted Storage
googleApiKeyRemovedDrop 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 keysCorrected spellingRename 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.

v3v4
layout.chatAI.grammerlayout.chatAI.grammar
layout.chatAI.questions.personalizatelayout.chatAI.questions.personalize
forms.GPA.not_quarantedforms.GPA.not_guaranteed
forms.settings_line_heigh_preciseforms.settings_line_height_precise
forms.settings_line_heigh_predefinedforms.settings_line_height_predefined
forms.settings_bgcforms.settings_background_color
forms.stuckforms.stack_columns
forms.do_not_stuckforms.do_not_stack_columns
errors.invalid_HTML_rowerrors.invalid_html_section
errors.fix_HTMLerrors.fix_html
product.recommenededproduct.recommended

Defaults that changed ​

These features are now on by default. Set the option explicitly to keep the v3 behaviour.

Optionv3 defaultv4 default
smartMergeTags.enabledfalsetrue
mobileFirstEnabledfalsetrue
premadeTemplatesfalsetrue
Control panel toggleHidden (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 onSave or onSaveAndClose returns 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 onSave finishes, and only if the template didn't change in the meantime.
  • Save & Close without onSaveAndClose now calls onSave and then closes the editor. In v3 nothing happened.
  • The window bar's close button without onEditorClose now closes the editor by itself.
  • Failed authentication reports onEditorError with source: "authorize", then source: "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.