Skip to content

Commit 542d65b

Browse files
authored
Merge pull request #189 from seznam/novinky-713
Improved visibility scroll listener performance by making it passive
2 parents 916ad62 + 5be91a5 commit 542d65b

File tree

9 files changed

+48
-55
lines changed

9 files changed

+48
-55
lines changed

.changeset/fuzzy-waves-pretend.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@ima/plugin-script-loader": patch
3+
"@ima/plugin-analytic": patch
4+
---
5+
6+
Updated to latest @ima/core

.changeset/new-rice-fry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ima/plugin-atoms": minor
3+
---
4+
5+
Improved visibility scroll listener performance by making it passive

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/plugin-analytic/src/AbstractAnalytic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,6 @@ export abstract class AbstractAnalytic {
154154
* @param eventType
155155
*/
156156
_fireLifecycleEvent(eventType: AnalyticEvents) {
157-
this.#dispatcher.fire(eventType, { type: this._analyticScriptName }, true);
157+
this.#dispatcher.fire(eventType, { type: this._analyticScriptName });
158158
}
159159
}

packages/plugin-analytic/src/__tests__/AbstractAnalyticSpec.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,9 @@ describe('AbstractAnalytic', () => {
7474
jest.spyOn(dispatcher, 'fire');
7575

7676
abstractAnalytic.init();
77-
expect(dispatcher.fire).toHaveBeenCalledWith(
78-
AnalyticEvents.INITIALIZED,
79-
{ type: 'dummy' },
80-
true
81-
);
77+
expect(dispatcher.fire).toHaveBeenCalledWith(AnalyticEvents.INITIALIZED, {
78+
type: 'dummy',
79+
});
8280
});
8381
});
8482

@@ -104,11 +102,9 @@ describe('AbstractAnalytic', () => {
104102

105103
expect(scriptLoader.load).toHaveBeenCalled();
106104
expect(abstractAnalytic._configuration).toHaveBeenCalled();
107-
expect(dispatcher.fire).toHaveBeenCalledWith(
108-
AnalyticEvents.LOADED,
109-
{ type: 'dummy' },
110-
true
111-
);
105+
expect(dispatcher.fire).toHaveBeenCalledWith(AnalyticEvents.LOADED, {
106+
type: 'dummy',
107+
});
112108
});
113109

114110
it('should load analytic script, call configuration method and fire loaded event only once.', async () => {
@@ -117,11 +113,9 @@ describe('AbstractAnalytic', () => {
117113

118114
expect(scriptLoader.load.mock.calls).toHaveLength(1);
119115
expect(abstractAnalytic._configuration.mock.calls).toHaveLength(1);
120-
expect(dispatcher.fire).toHaveBeenCalledWith(
121-
AnalyticEvents.LOADED,
122-
{ type: 'dummy' },
123-
true
124-
);
116+
expect(dispatcher.fire).toHaveBeenCalledWith(AnalyticEvents.LOADED, {
117+
type: 'dummy',
118+
});
125119
expect(dispatcher.fire.mock.calls).toHaveLength(1);
126120
});
127121
});

packages/plugin-atoms/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
},
3535
"license": "MIT",
3636
"peerDependencies": {
37-
"@ima/core": ">=18.0.0",
38-
"@ima/react-page-renderer": ">=18.0.0",
39-
"@ima/plugin-useragent": ">=5.0.0"
37+
"@ima/core": ">=19.6.3",
38+
"@ima/plugin-useragent": ">=5.0.0",
39+
"@ima/react-page-renderer": ">=18.0.0"
4040
},
4141
"dependencies": {
4242
"infinite-circle": "^0.3.0"

packages/plugin-atoms/src/Visibility.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ export default class Visibility {
137137
this
138138
);
139139
this._window.bindEventListener(this._window.getWindow()!, 'resize', notify);
140-
this._window.bindEventListener(this._window.getWindow()!, 'scroll', notify);
140+
this._window.bindEventListener(
141+
this._window.getWindow()!,
142+
'scroll',
143+
notify,
144+
{ passive: true }
145+
);
141146
}
142147

143148
/**

packages/plugin-script-loader/src/ScriptLoader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class ScriptLoader {
9393
*/
9494
_handleOnLoad(url: string) {
9595
const data = { url };
96-
this._dispatcher.fire(Events.LOADED, data, true);
96+
this._dispatcher.fire(Events.LOADED, data);
9797

9898
return data;
9999
}
@@ -112,7 +112,7 @@ export class ScriptLoader {
112112
error,
113113
};
114114

115-
this._dispatcher.fire(Events.LOADED, data, true);
115+
this._dispatcher.fire(Events.LOADED, data);
116116
throw error;
117117
}
118118
}

packages/plugin-script-loader/src/__tests__/ScriptLoaderSpec.js

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ describe('ScriptLoader', () => {
6666

6767
await scriptLoaderPlugin.load(url, template);
6868

69-
expect(dispatcher.fire).toHaveBeenCalledWith(
70-
Events.LOADED,
71-
{ url },
72-
true
73-
);
69+
expect(dispatcher.fire).toHaveBeenCalledWith(Events.LOADED, { url });
7470
});
7571

7672
it('the dispatcher fire loaded event for scripts loaded by url', async () => {
@@ -81,11 +77,7 @@ describe('ScriptLoader', () => {
8177

8278
await scriptLoaderPlugin.load(url);
8379

84-
expect(dispatcher.fire).toHaveBeenCalledWith(
85-
Events.LOADED,
86-
{ url },
87-
true
88-
);
80+
expect(dispatcher.fire).toHaveBeenCalledWith(Events.LOADED, { url });
8981
});
9082

9183
it('the dispatcher fire loaded event with errors', async () => {
@@ -97,11 +89,10 @@ describe('ScriptLoader', () => {
9789
try {
9890
await scriptLoaderPlugin.load(url);
9991
} catch (error) {
100-
expect(dispatcher.fire).toHaveBeenCalledWith(
101-
Events.LOADED,
102-
{ url, error },
103-
true
104-
);
92+
expect(dispatcher.fire).toHaveBeenCalledWith(Events.LOADED, {
93+
url,
94+
error,
95+
});
10596
}
10697
});
10798

@@ -113,11 +104,7 @@ describe('ScriptLoader', () => {
113104

114105
await scriptLoaderPlugin.load(url);
115106

116-
expect(dispatcher.fire).toHaveBeenCalledWith(
117-
Events.LOADED,
118-
{ url },
119-
true
120-
);
107+
expect(dispatcher.fire).toHaveBeenCalledWith(Events.LOADED, { url });
121108

122109
jest.clearAllMocks();
123110
await scriptLoaderPlugin.load(url);
@@ -126,11 +113,7 @@ describe('ScriptLoader', () => {
126113

127114
await scriptLoaderPlugin.load(url, null, true);
128115

129-
expect(dispatcher.fire).toHaveBeenCalledWith(
130-
Events.LOADED,
131-
{ url },
132-
true
133-
);
116+
expect(dispatcher.fire).toHaveBeenCalledWith(Events.LOADED, { url });
134117
});
135118
});
136119
});

0 commit comments

Comments
 (0)