Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Data: clear hasDataAttrs on full .removeData() call#5849

Open
sawirricardo wants to merge 1 commit into
jquery:mainfrom
sawirricardo:fix-removedata-hasdataattrs
Open

Data: clear hasDataAttrs on full .removeData() call#5849
sawirricardo wants to merge 1 commit into
jquery:mainfrom
sawirricardo:fix-removedata-hasdataattrs

Conversation

@sawirricardo

Copy link
Copy Markdown

Summary

Fixes gh-5751

The hasDataAttrs private flag was not cleared when .removeData() was called without a key argument. This prevented subsequent .data() calls from re-reading HTML5 data-* attributes, contrary to the documented behavior:

A later call to data() will [...] re-retrieve the value from the data- attribute.

Reproduction

const elem = $("<div data-test=\"123\">");
console.log(elem.data("test")); // 123
elem.removeData();
console.log(elem.data("test")); // Expected: 123, Actual before fix: undefined

Fix

Clear dataPriv's hasDataAttrs flag when .removeData() is called without a specific key (full data removal). When a key is passed, the flag is left intact since individual key removal should not trigger a full data-attr re-scan.

Test plan

Added QUnit test .removeData() clears hasDataAttrs so data-* attributes are re-read (gh-5751) verifying the documented behavior.

The hasDataAttrs flag was not cleared when .removeData() was called
without a key, preventing subsequent .data() calls from re-reading
HTML5 data-* attributes as documented.

Fixes jquerygh-5751
@linux-foundation-easycla

Copy link
Copy Markdown

CLA Not Signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Calling elem.removeData() then elem.data() causes data- attributes not to be repopulated

1 participant