fix(editor): preserve custom HTML by blocking lossy visual conversion#362
fix(editor): preserve custom HTML by blocking lossy visual conversion#362heyramzi wants to merge 2 commits into
Conversation
|
The reason the destructive action is there in case there is an edge where a template gets incorrectly identified but is parseable. This would allow the user to switch between modes, in your solution this is no longer possible. To completely lose a template you would need to press the destructive button AND save the template. You can always refresh the page to discard the changes. |
Instead of blocking the HTML→Visual switch for custom HTML templates, allow the switch but snapshot the original HTML. A revert banner lets the user restore the original markup if the visual conversion dropped elements. This addresses the maintainer's concern about false positives in custom HTML detection while still protecting against accidental loss. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Good point about false positives in the detection. I've revised the approach: Before: Block the switch entirely when custom HTML is detected. This way:
The snapshot is cleared when switching back to HTML mode or when the user dismisses the banner. |
Summary
Prevent templates with unsupported custom HTML from switching into the visual editor, where the markup would be normalized into a lossy TipTap representation.
Problem
The editor already detects custom HTML and warns that visual mode cannot preserve it faithfully. But the current dialog still offers a destructive
Switch Anywaypath, which makes it too easy to mutate production email markup accidentally.This is especially risky for templates that depend on:
What changed
Switch Anywaypath from the custom HTML warning dialogWhy this approach
The safe path already exists: users can continue editing in HTML mode and still preview the rendered email without converting the source into visual-editor content. Blocking the destructive transition preserves the original template instead of asking users to make an unsafe choice.
Verification
yarn vitest run --config ./vitest.mode-guards.config.cjs apps/web/__tests__/EmailEditor/modeGuards.test.tsNote: the repository's default Vitest setup requires a database and runs global DB initialization for all suites, so I used a minimal temporary config to verify this pure unit test in isolation.