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

PBjs Utils: Faster Deep Clone #11418

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion allowedModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
],
'src': [
'fun-hooks/no-eval',
'just-clone',
'klona',
'dlv',
'dset'
],
Expand Down
2 changes: 1 addition & 1 deletion modules/browsiRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function addBrowsiTag(data) {
script.setAttribute('prebidbpt', 'true');
script.setAttribute('id', 'browsi-tag');
script.setAttribute('src', data.u);
script.prebidData = deepClone(data);
script.prebidData = deepClone(typeof data === 'string' ? Object(data) : data)
Copy link
Contributor Author

@bbaresic bbaresic Apr 29, 2024

Choose a reason for hiding this comment

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

Version 1 of just-clone casts everything to an object, even though in this case it was a string (I am not sure if this was wanted behavior, but it resulted in a failed test).

The newer versions don't do that, just like klona.

This is here to preserve that behavior.

if (_moduleParams.keyName) {
script.prebidData.kn = _moduleParams.keyName;
}
Expand Down
25 changes: 14 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"express": "^4.15.4",
"fun-hooks": "^0.9.9",
"gulp-wrap": "^0.15.0",
"just-clone": "^1.0.2",
"klona": "^2.0.6",
"live-connect-js": "^6.3.4"
},
"optionalDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {config} from './config.js';
import clone from 'just-clone';
import {klona} from 'klona/json';
import {includes} from './polyfill.js';
import { EVENTS, S2S } from './constants.js';
import {GreedyPromise} from './utils/promise.js';
Expand Down Expand Up @@ -609,7 +609,7 @@ export function shuffle(array) {
}

export function deepClone(obj) {
return clone(obj);
return klona(obj) || {};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Version 1 of just-clone gives back an empty object when the cloning fails.

The newer versions don't do that, just like klona.

This is here to preserve that behavior.

}

export function inIframe() {
Expand Down