-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: Structure board update sometimes failed to add all interactive elements #8227
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
fix: Scan plugin data after structure mode Xhr load
- Loading branch information
commit 0ea28e5e22b87b7dd298fee25b3392237bbb5529
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,22 +395,19 @@ class StructureBoard { | |
CMS.settings.states = Helpers.getSettings().states; | ||
|
||
const bodyRegex = /<body[\S\s]*?>([\S\s]*)<\/body>/gi; | ||
const body = $(bodyRegex.exec(contentMarkup)[1]); | ||
const body = document.createElement("div"); // Switch to plain JS due to problem with $(body) | ||
body.innerHTML = bodyRegex.exec(contentMarkup)[1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Guard against null return from Assign |
||
|
||
const structure = body.find('.cms-structure-content'); | ||
const toolbar = body.find('.cms-toolbar'); | ||
const scripts = body.filter(function() { | ||
return $(this).is('[type="text/cms-template"]'); // cms scripts | ||
}); | ||
const pluginIds = this.getIds(body.find('.cms-draggable')); | ||
const pluginDataSource = body.filter('script[data-cms]').toArray() | ||
.map(script => script.textContent || '').join(); | ||
const structure = $(body.querySelector('.cms-structure-content')); | ||
const toolbar = $(body.querySelector('.cms-toolbar')); | ||
const scripts = $(body.querySelector('[type="text/cms-template"]')); // cms scripts | ||
const pluginIds = this.getIds($(body.querySelectorAll('.cms-draggable'))); | ||
const pluginData = StructureBoard._getPluginDataFromMarkup( | ||
pluginDataSource, | ||
body, | ||
pluginIds | ||
); | ||
|
||
Plugin._updateRegistry(pluginData.map(([, data]) => data)); | ||
Plugin._updateRegistry(pluginData); | ||
|
||
CMS.API.Toolbar._refreshMarkup(toolbar); | ||
|
||
|
@@ -1744,21 +1741,19 @@ class StructureBoard { | |
* | ||
* @method _getPluginDataFromMarkup | ||
* @private | ||
* @param {String} markup | ||
* @param {Node} body | ||
* @param {Array<Number | String>} pluginIds | ||
* @returns {Array<[String, Object]>} | ||
*/ | ||
static _getPluginDataFromMarkup(markup, pluginIds) { | ||
static _getPluginDataFromMarkup(body, pluginIds) { | ||
return compact( | ||
pluginIds.map(pluginId => { | ||
// oh boy | ||
const regex = new RegExp(`CMS._plugins.push\\((\\["cms\-plugin\-${pluginId}",[\\s\\S]*?\\])\\)`, 'g'); | ||
const matches = regex.exec(markup); | ||
const pluginData = body.querySelector(`#cms-plugin-${pluginId}`); | ||
let settings; | ||
|
||
if (matches) { | ||
if (pluginData) { | ||
try { | ||
settings = JSON.parse(matches[1]); | ||
settings = JSON.parse(pluginData.textContent); | ||
} catch (e) { | ||
settings = false; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Remove the global flag from bodyRegex to avoid stateful exec issues
RegExp.exec with
g
is stateful and can return null on reuse; remove theg
flag since only a single match is needed.