Skip to content
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

Fix ensure blocks array not null before component update #1294

Merged

Conversation

satrun77
Copy link
Contributor

@satrun77 satrun77 commented Dec 12, 2024

Description

Ensure blocks properties in ElementList::componentDidUpdate are not null before calling map method. This is to prevent breaking the elemental area field while it is rendering, and the content author clicks the save or publish buttons too quickly.

Manual testing steps

  1. Install fresh CMS
  2. Add Elemental module
  3. Create a data object with version and more than one elemental area
use DNADesign\Elemental\Extensions\ElementalPageExtension;
use DNADesign\Elemental\Models\ElementalArea;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;

class SomeObject extends DataObject
{
    private static string $table_name = 'SomeObject';

    private static array $db = [
        'Title' => 'Text',
    ];

    private static array $has_one = [
        'BlockArea' => ElementalArea::class,
        'BlockArea2' => ElementalArea::class,
    ];

    private static array $extensions = [
        Versioned::class,
        ElementalPageExtension::class,
    ];
}
  1. Create a model admin for the data object.
use SilverStripe\Admin\ModelAdmin;

class SomeAdmin extends ModelAdmin
{
    private static string $url_segment = 'objects';

    private static string $menu_title = 'Objects';

    private static array $managed_models = [
        SomeObject::class,
    ];
}
  1. Open browser console > Network tab
  2. You will see multiple requests for /admin/graphql for each elemental area
Screenshot 2024-12-11 at 1 50 16 PM
  1. Click publish just before all of the requests are completed, and you will see the pending ones changed to cancelled. The requests may load fast, which makes it hard to replicate. I edited the controller SilverStripe\GraphQL\Controller, and added sleep(1); to index method to slow down the request.
Screenshot 2024-12-11 at 1 50 55 PM
  1. Saving or publishing the data object must be completed without any issue
  2. The error about accessing map on null, must not be throwing in the console
Screenshot 2024-12-13 at 10 45 33 AM

Issues

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, works locally. I can't think of a way this would cause new problems so should be fine in a patch. Thanks for submitting this!

@GuySartorelli GuySartorelli merged commit 3b70c8e into silverstripe:5.3 Dec 12, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants