-
-
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
Conversation
Reviewer's GuideRefactors structure board parsing from regex/jQuery to DOM-based methods by using a div container, document.querySelector, and JSON-parsed script tags, updates the _getPluginDataFromMarkup signature and Plugin._updateRegistry invocation, and adjusts unit tests to match the new data extraction approach. File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Yes, this PR request fixes our problem. Thanks @fsbraun
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.
Hey @fsbraun - I've reviewed your changes - here's some feedback:
- Cache the result of bodyRegex.exec(contentMarkup) (or remove the “g” flag) to avoid running the regex twice and guard against null matches before accessing the capture group.
- Consider using DOMParser.parseFromString instead of creating a div and setting innerHTML directly for more robust and secure HTML parsing.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@@ -395,22 +395,20 @@ class StructureBoard { | |||
CMS.settings.states = Helpers.getSettings().states; | |||
|
|||
const bodyRegex = /<body[\S\s]*?>([\S\s]*)<\/body>/gi; |
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 the g
flag since only a single match is needed.
const bodyRegex = /<body[\S\s]*?>([\S\s]*)<\/body>/gi; | |
const bodyRegex = /<body[\S\s]*?>([\S\s]*)<\/body>/i; |
const pluginIds = this.getIds(body.find('.cms-draggable')); | ||
const pluginDataSource = body.filter('script[data-cms]').toArray() | ||
.map(script => script.textContent || '').join(); | ||
body.innerHTML = bodyRegex.exec(contentMarkup)[1]; |
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): Guard against null return from exec
before indexing
Assign bodyRegex.exec(contentMarkup)
to a variable and verify it’s not null before accessing [1]
to prevent a runtime error when there’s no match.
…lements (#8227) * fix: Scan plugin data after structure mode Xhr load * Fix test * fix js linting issues
…lements (#8227) * fix: Scan plugin data after structure mode Xhr load * Fix test * fix js linting issues
* [5.1.0dev1 release process] Bumped version to 5.1.0dev1 * [5.1.0dev1 release process] compilemessages * [5.1.0dev1 release process] compiling new static files * [5.1.0dev1 release process] updating latest docs * Prepare new main branch * Fix typos * fix: No changes to changelog * fix: Remove unnecessary change to migration * Remove circular import * Fix import order * Re-introduce dummy `PlaceholderField` for legacy migrations * fix: Do not assume page url cache to be filled * fix: Structure board update sometimes failed to add all interactive elements (#8227) * fix: Scan plugin data after structure mode Xhr load * Fix test * fix js linting issues * fix: Update assets * fix: Empty plugin selectors in all but first placeholder * fix: Add slotname argument to dummy `PlaceholderField` * fix: Adjust checks for `GrouperAdmin` to allow for `prepopulated_fields` (#8232) * fix: Adjust checks for GrouperAdmin to allow for `prepopulated_fields` * Update cms/tests/test_grouper_admin.py --------- Co-authored-by: Github Release Action <info@django-cms.org>
…#8233) * [5.1.0dev1 release process] Bumped version to 5.1.0dev1 * [5.1.0dev1 release process] compilemessages * [5.1.0dev1 release process] compiling new static files * [5.1.0dev1 release process] updating latest docs * Prepare new main branch * Fix typos * fix: No changes to changelog * fix: Remove unnecessary change to migration * Remove circular import * Fix import order * Re-introduce dummy `PlaceholderField` for legacy migrations * fix: Do not assume page url cache to be filled * fix: Structure board update sometimes failed to add all interactive elements (#8227) * fix: Scan plugin data after structure mode Xhr load * Fix test * fix js linting issues * fix: Update assets * fix: Empty plugin selectors in all but first placeholder * chore: Move from script tags containing dom elements to template tags * Update cms/models/fields.py * Update cms/models/fields.py --------- Co-authored-by: Github Release Action <info@django-cms.org>
…#8233) * [5.1.0dev1 release process] Bumped version to 5.1.0dev1 * [5.1.0dev1 release process] compilemessages * [5.1.0dev1 release process] compiling new static files * [5.1.0dev1 release process] updating latest docs * Prepare new main branch * Fix typos * fix: No changes to changelog * fix: Remove unnecessary change to migration * Remove circular import * Fix import order * Re-introduce dummy `PlaceholderField` for legacy migrations * fix: Do not assume page url cache to be filled * fix: Structure board update sometimes failed to add all interactive elements (#8227) * fix: Scan plugin data after structure mode Xhr load * Fix test * fix js linting issues * fix: Update assets * fix: Empty plugin selectors in all but first placeholder * chore: Move from script tags containing dom elements to template tags * Update cms/models/fields.py * Update cms/models/fields.py --------- Co-authored-by: Github Release Action <info@django-cms.org>
…#8233) (#8237) * [5.1.0dev1 release process] Bumped version to 5.1.0dev1 * [5.1.0dev1 release process] compilemessages * [5.1.0dev1 release process] compiling new static files * [5.1.0dev1 release process] updating latest docs * Prepare new main branch * Fix typos * fix: No changes to changelog * fix: Remove unnecessary change to migration * Remove circular import * Fix import order * Re-introduce dummy `PlaceholderField` for legacy migrations * fix: Do not assume page url cache to be filled * fix: Structure board update sometimes failed to add all interactive elements (#8227) * fix: Scan plugin data after structure mode Xhr load * Fix test * fix js linting issues * fix: Update assets * fix: Empty plugin selectors in all but first placeholder * chore: Move from script tags containing dom elements to template tags * Update cms/models/fields.py * Update cms/models/fields.py --------- Co-authored-by: Github Release Action <info@django-cms.org>
* fix: Remove circular import in `cms.forms.validators` (#8225) * Remove circular import * Fix linting * Update cms/forms/validators.py * fix: Do not assume page url cache is filled * fix: Structure board update sometimes failed to add all interactive elements (#8227) * fix: Scan plugin data after structure mode Xhr load * Fix test * fix js linting issues * fix: Empty plugin selectors in all but first placeholder * fix: Show all text-enabled plugins (#8229) * fix: Adjust checks for GrouperAdmin to allow for `prepopulated_fields` * fix: Page settings raised an exception when `USE_I18N = False` * update ruff check * Fix pk reference --------- Co-authored-by: Vinit Kumar <mail@vinitkumar.me>
Description
When opening the edit endpoint under (not entirely clear) circumstances not all plugin data inside the structure markup is recognized. This leads to some items in the structure board to be missing interaction handlers.
Reason is an outdated regex for inline javascript (which has been removed in django CMS 5.0).
Related resources
Screen_Recording_2025-05-13_at_16.36.54.mov
Checklist
main
Summary by Sourcery
Fix struct 8000 ure board update to reliably add all interactive elements by replacing outdated regex-based parsing with native DOM querying and update associated tests.
Bug Fixes:
Enhancements:
document.createElement
,querySelector
) instead of jQuery and regex_getPluginDataFromMarkup
to extract plugin settings from<script>
elementsTests:
_getPluginDataFromMarkup
and validate the new plugin data extraction output