mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Added double-encoded fix to mobiledoc->lexical snippets sync
no issue Early in the editor beta snippets were being saved with double-encoded JSON meaning we were dealing with strings rather than objects after Ember's deserialization. That's since been fixed so we're dealing with objects everywhere but old data can still cause issues. - added a step to the `syncMobiledocSnippets()` method that checks if `snippet.lexical` is a string and performs the necessary fixes to the double-encoded values - updated the snippet filter in the old editor to exclude double-encoded snippets as that could still load before the new editor has been accessed and the sync+fix has run
This commit is contained in:
parent
ed24899fa5
commit
d5a547b6ad
2 changed files with 19 additions and 2 deletions
|
@ -173,7 +173,7 @@ export default class EditorController extends Controller {
|
|||
get snippets() {
|
||||
return this._snippets
|
||||
.reject(snippet => snippet.get('isNew'))
|
||||
.reject(snippet => JSON.stringify(snippet.mobiledoc) === '{}')
|
||||
.reject(snippet => ['{}', '"{}"'].includes(JSON.stringify(snippet.mobiledoc)))
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
|
|
|
@ -782,9 +782,26 @@ export default class LexicalEditorController extends Controller {
|
|||
}
|
||||
|
||||
@action
|
||||
syncMobiledocSnippets() {
|
||||
async syncMobiledocSnippets() {
|
||||
const snippets = this.store.peekAll('snippet');
|
||||
|
||||
// very early in the beta we had a bug where lexical snippets were saved with double-encoded JSON
|
||||
// we fix that here by re-saving any snippets that are still in that state
|
||||
const snippetFixSaves = [];
|
||||
snippets.forEach((snippet) => {
|
||||
if (typeof snippet.lexical === 'string') {
|
||||
try {
|
||||
snippet.lexical = JSON.parse(snippet.lexical);
|
||||
snippet.mobiledoc = {};
|
||||
snippetFixSaves.push(snippet.save());
|
||||
} catch (e) {
|
||||
snippet.lexical = null;
|
||||
snippetFixSaves.push(snippet.save());
|
||||
}
|
||||
}
|
||||
});
|
||||
await Promise.all(snippetFixSaves);
|
||||
|
||||
snippets.forEach((snippet) => {
|
||||
if (!snippet.lexical || snippet.lexical.syncedAt && moment.utc(snippet.lexical.syncedAt).isBefore(snippet.updatedAtUTC)) {
|
||||
const serializedLexical = mobiledocToLexical(JSON.stringify(snippet.mobiledoc));
|
||||
|
|
Loading…
Add table
Reference in a new issue