• Plugin 1.4.0 · ACF PRO 6.8.10 · WordPress 7.1 Summary

    GREAT plugin, first off.

    With this plugin active, ACF’s flexible content field loses its collapsed-layout memory:
    every layout renders expanded on each page load. Deactivating the plugin restores the
    behavior immediately. The page I’m editing has ~56 flexible content layouts, so this is
    the difference between a usable editor screen and an unusable one. Steps to reproduce

    1. A post type with an ACF PRO flexible content field holding many layouts.
    2. At least one of those layouts contains a Table field.
    3. Collapse some or all layouts. Reload the page.

    Expected: layouts return collapsed.
    Actual: every layout is expanded again. What I found

    ACF PRO stores flexible content collapse state in localStorage under the key “acf”,
    as collapsedLayouts-<postID>, handled by the this.collapsedLayouts model in
    assets/build/js/pro/acf-pro-input.min.js. That model builds its storage key like this:

    key: function(key, context) {        // context = "load" or "save"
        var count = this.get(key + context) || 0;
        count++;
        this.set(key + context, count, true);
        if (count > 1) key += '-' + count;
        return key;
    }

    So if the same field asks for its state more than once in a single page load, the
    second request gets a DIFFERENT key with a “-2” suffix. Load and save keep separate
    counters, so reads and writes can end up on opposite sides of that suffix.

    That is exactly what I see in localStorage with the plugin active:

    collapsedLayouts-1511: {
        field_610ac7050d4ff:   Array(56),
        field_610ac7050d4ff-2: Array(55)
    }

    One field, two entries. With the plugin deactivated, only the unsuffixed key appears
    and collapse state persists correctly. Suspected cause

    js/init.js attaches a MutationObserver to the entire document, unconditionally, whether
    or not a Table field is present on the screen:

    mutationObserver.observe( document.documentElement, {
        childList: true,
        subtree: true,
    });

    Each batch re-arms a 250ms timer that calls update_tables() -> each_table(), which then
    mutates the DOM itself (adds classes, injects .acf-table-wrap) and so re-triggers its own
    observer. On an ACF admin screen with a large flexible content field, that churn overlaps
    the window in which ACF initializes the field, and the field ends up initialized more than
    once — which mints the suffixed key above.

    I have not instrumented the double initialization directly; that part is inferred from
    ACF’s key-suffixing behavior plus the observed “-2” entry. What is directly confirmed is
    that the “-2” key appears only while this plugin is active. Suggested fix

    Scope the observer rather than watching the whole document:

    • observe only a container that can actually contain table fields, or
    • skip attaching it entirely when no .acf-table-root exists on the page, or
    • prefer ACF’s own append / ready actions over a MutationObserver, which is how ACF
      expects add-ons to learn about new fields, and
    • optionally offer a constant to opt out, in the spirit of the existing
      ACF_TABLEFIELD_FILTER_POSTMETA.

    Happy to test a patch against the above setup.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Johann Heyne

    (@jonua)

    Hi brethummel,

    Thank you for the detailed description of the issue. Unfortunately, I haven’t been able to reproduce this behavior yet.

    I created a Flexible Content field for pages with 70 different layouts (one of them containing a Table Field), and on a page I used 70 layout entries, including the one with the table field. But there was no duplicate entry for the field in the collapsedLayouts localStorage key, and all layouts remained collapsed after reloading the page.

    The setInterval inside the MutationObserver ensures that the interval callback is executed only once after all mutations on page load. Additionally, the condition if ($('.acf-table-root').not('.acf-table-rendered').length > 0) ensures that initialization only runs when non‑initialized table fields exist on a mutation. This is usually not the case on the initial page load. This solution isn’t ideal, but it covers all possible scenarios in which the table field needs to be initialized.

    However, there may be an issue caused by too many setInterval() and clearInterval() calls triggered by the MutationObserver. I replaced the interval with requestAnimationFrame to avoid a possible problem. This is step 1 to try.

    You can test this change with version 1.4.1‑RC1.
    https://downloads.wordpress.org/plugin/advanced-custom-fields-table-field.1.4.0-RC1.zip

    If that doesn’t resolve the issue, I also have an alternative variant that uses ACF’s own actions, among other adjustments.

    Let me know.
    Cheers,
    Johann

    Plugin Author Johann Heyne

    (@jonua)

    1.4.1-RC2 fixes firing update_tables() too early, which caused the _acf_changed meta error.
    https://downloads.wordpress.org/plugin/advanced-custom-fields-table-field.1.4.1-RC2.zip

    This may also fixes the flexible content field collapsed-layout memory issue.

    Thread Starter brethummel

    (@brethummel)

    Sorry, I hadn’t been able to track this. I’m going go download your RC2 and give it a whirl. Thanks for your response!!

    Bret

    Thread Starter brethummel

    (@brethummel)

    I can confirm that fixes the problem I was seeing. You’re the best! I’ll watch for the official update.

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.