Skip to content

Commit

Permalink
Fork ResizeObserver polyfill to support shadow DOM and FIE (#31850)
Browse files Browse the repository at this point in the history
* Upgrade ResizeObserver polyfill to support shadow DOM and FIE

* dep check fixed
  • Loading branch information
Dima Voytenko authored Jan 8, 2021
1 parent 3faf977 commit 4209fe9
Show file tree
Hide file tree
Showing 9 changed files with 2,408 additions and 4 deletions.
3 changes: 2 additions & 1 deletion build-system/compile/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const COMMON_GLOBS = [
'third_party/inputmask/**/*.js',
'third_party/mustache/**/*.js',
'third_party/react-dates/bundle.js',
'third_party/resize-observer-polyfill/ResizeObserver.install.js',
'third_party/set-dom/set-dom.js',
'third_party/subscriptions-project/*.js',
'third_party/timeagojs/**/*.js',
Expand All @@ -41,7 +42,7 @@ const COMMON_GLOBS = [
'node_modules/intersection-observer/package.json',
'node_modules/intersection-observer/intersection-observer.install.js',
'node_modules/resize-observer-polyfill/package.json',
'node_modules/resize-observer-polyfill/resize-observer.install.js',
'node_modules/resize-observer-polyfill/ResizeObserver.install.js',
'node_modules/promise-pjs/package.json',
'node_modules/promise-pjs/promise.mjs',
'node_modules/rrule/dist/es5/rrule.js',
Expand Down
4 changes: 2 additions & 2 deletions build-system/tasks/update-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ function patchIntersectionObserver() {
function patchResizeObserver() {
// Copies intersection-observer into a new file that has an export.
const patchedName =
'node_modules/resize-observer-polyfill/resize-observer.install.js';
'node_modules/resize-observer-polyfill/ResizeObserver.install.js';
let file = fs
.readFileSync(
'node_modules/resize-observer-polyfill/dist/ResizeObserver.global.js'
'node_modules/resize-observer-polyfill/dist/ResizeObserver.js'
)
.toString();

Expand Down
1 change: 1 addition & 0 deletions build-system/test-configs/dep-check-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ exports.rules = [
'extensions/amp-list/**->third_party/set-dom/set-dom.js',
'extensions/amp-mustache/**/amp-mustache.js->third_party/mustache/mustache.js',
'extensions/amp-recaptcha-input/**/*.js->third_party/amp-toolbox-cache-url/dist/amp-toolbox-cache-url.esm.js',
'extensions/amp-resize-observer-polyfill/**/*.js->third_party/resize-observer-polyfill/ResizeObserver.install.js',
'extensions/amp-story-360/0.1/amp-story-360.js->third_party/zuho/zuho.js',
'extensions/amp-subscriptions-google/**/*.js->third_party/subscriptions-project/swg.js',
'extensions/amp-subscriptions/**/*.js->third_party/subscriptions-project/aes_gcm.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {installResizeObserver} from 'resize-observer-polyfill/resize-observer.install';
import {installResizeObserver} from '../../../third_party/resize-observer-polyfill/ResizeObserver.install';
import {registerServiceBuilder} from '../../../src/service';
import {upgradePolyfill} from '../../../src/polyfillstub/resize-observer-stub';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright 2021 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
ResizeObserverStub,
installStub,
} from '../../../../src/polyfillstub/resize-observer-stub';
import {upgradeResizeObserverPolyfill} from '../amp-resize-observer-polyfill';

describes.realWin('amp-resize-observer-polyfill', {amp: false}, (env) => {
let win;

beforeEach(() => {
win = env.win;
delete win.ResizeObserver;
installStub(win);
});

it('should install ResizeObserver polyfill', () => {
expect(win.ResizeObserver).to.equal(ResizeObserverStub);
upgradeResizeObserverPolyfill(win);
expect(win.ResizeObserver).to.exist;
expect(win.ResizeObserver).to.not.equal(ResizeObserverStub);
});
});
21 changes: 21 additions & 0 deletions third_party/resize-observer-polyfill/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Denis Rul

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions third_party/resize-observer-polyfill/README.amp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
URL: https://github.com/que-etc/resize-observer-polyfill
Fork URL: https://github.com/dvoytenko/resize-observer-polyfill
License: MIT License
License File: https://github.com/que-etc/resize-observer-polyfill/blob/master/LICENSE

Description:
A polyfill for the ResizeObserver API.

The original [polyfill](https://github.com/que-etc/resize-observer-polyfill) has
been [forked](https://github.com/dvoytenko/resize-observer-polyfill) to enable
this polyfill to work across the boundary of Shadow DOM and same-origin
iframes. See https://github.com/que-etc/resize-observer-polyfill/pull/79 for
more details. As soon as this pull request has been merged, the AMP project
will switch to [NPM dependency](https://www.npmjs.com/package/resize-observer-polyfill).

Local modifications:
- The installer is wrapped into `installResizeObserver` function. See `ResizeObserver.install.js`.
Loading

0 comments on commit 4209fe9

Please sign in to comment.