Skip to content

[Regression] getState method returns no data in event callback #100

@gabrielwalt

Description

@gabrielwalt

When pushing a callback on the adobeDataLayer stack that is to be executed as soon as the adobeDataLayer object initializes, then it seems that adobeDataLayer.getState() doesn't work properly.

This worked in 1.0.0, even though incorrectly as the callbacks got called twice: once with the data not available via adobeDataLayer.getState() and once with the data available. In 1.1.0, the callback is called once only, but only with no more data available via adobeDataLayer.getState().

Steps to reproduce

Navigate to about:blank URL in a browser, and execute the following JS in the brower console:

window.adobeDataLayer = [];
instance = 0;

adobeDataLayer.push(function(dl) {
    dl.addEventListener(
        "new event", 
        function(event) {
            console.log("callback " + ++instance, dl.getState());
        }
    )
});

adobeDataLayer.push({
    event: "new event",
    context: "test"
});

acdl = document.createElement("script");
acdl.src = "https://unpkg.com/@adobe/adobe-client-data-layer@1.1.0/dist/adobe-client-data-layer.min.js";
document.body.append(acdl);

The above code incorrectly logs:

callback 1 {}

It would have been expected to log:

callback 1 { context: "test" }

When changing the adobe-client-data-layer script version to 1.0.0, then the callback gets wrongly executed twice, but the second time with the correct data available:

callback 1 {}
callback 2 { context: "test" }

This change was introduced via #92, and it seems like it didn't correctly fix the entire problem.

Metadata

Metadata

Assignees

Labels

bugUnexpected problem or unintended behavior that impairs normal functioning.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions