Skip to content

Commit 402e70b

Browse files
authored
fix(template-compiler): disable static content optimization for iframes (#4678)
1 parent 1a30dec commit 402e70b

File tree

6 files changed

+46
-11
lines changed

6 files changed

+46
-11
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { createElement } from 'lwc';
2+
import Component from 'x/component';
3+
4+
let spy;
5+
6+
beforeEach(() => {
7+
spy = spyOn(Element.prototype, 'setAttribute');
8+
});
9+
10+
it('renders iframes correctly - W-17015807', async () => {
11+
const elm = createElement('x-component', { is: Component });
12+
document.body.appendChild(elm);
13+
14+
await Promise.resolve();
15+
16+
expect(spy).toHaveBeenCalledOnceWith('src', 'about:blank');
17+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<iframe src="about:blank"></iframe>
3+
</template>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { LightningElement } from 'lwc';
2+
3+
export default class extends LightningElement {}

packages/@lwc/template-compiler/src/__tests__/fixtures/attributes/attribute-allow/expected.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import _implicitStylesheets from "./attribute-allow.css";
22
import _implicitScopedStylesheets from "./attribute-allow.scoped.css?scoped=true";
3-
import { freezeTemplate, parseFragment, registerTemplate } from "lwc";
4-
const $fragment1 = parseFragment`<iframe allow="geolocation https://google-developers.appspot.com"${3}></iframe>`;
3+
import { freezeTemplate, registerTemplate } from "lwc";
4+
const stc0 = {
5+
attrs: {
6+
allow: "geolocation https://google-developers.appspot.com",
7+
},
8+
key: 0,
9+
};
510
function tmpl($api, $cmp, $slotset, $ctx) {
6-
const { st: api_static_fragment } = $api;
7-
return [api_static_fragment($fragment1, 1)];
11+
const { h: api_element } = $api;
12+
return [api_element("iframe", stc0)];
813
/*LWC compiler vX.X.X*/
914
}
1015
export default registerTemplate(tmpl);

packages/@lwc/template-compiler/src/__tests__/fixtures/static-content/no-escaping-tags/expected.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@ import _implicitStylesheets from "./no-escaping-tags.css";
22
import _implicitScopedStylesheets from "./no-escaping-tags.scoped.css?scoped=true";
33
import { freezeTemplate, parseFragment, registerTemplate } from "lwc";
44
const $fragment1 = parseFragment`<xmp${3}>&lt;/xmp&gt;Hello &lt;div&gt;world&lt;/div&gt; <div>foo</div></xmp>`;
5-
const $fragment2 = parseFragment`<iframe${3}>Hello &lt;div&gt;world&lt;/div&gt; <div>foo</div></iframe>`;
6-
const $fragment3 = parseFragment`<noembed${3}>Hello &lt;div&gt;world&lt;/div&gt; <div>foo</div></noembed>`;
7-
const $fragment4 = parseFragment`<noframes${3}><p>It seems your browser does not support frames or is configured to not allow them.</p></noframes>`;
5+
const $fragment2 = parseFragment`<noembed${3}>Hello &lt;div&gt;world&lt;/div&gt; <div>foo</div></noembed>`;
6+
const $fragment3 = parseFragment`<noframes${3}><p>It seems your browser does not support frames or is configured to not allow them.</p></noframes>`;
7+
const stc0 = {
8+
key: 2,
9+
};
810
function tmpl($api, $cmp, $slotset, $ctx) {
9-
const { st: api_static_fragment } = $api;
11+
const { st: api_static_fragment, t: api_text, h: api_element } = $api;
1012
return [
1113
api_static_fragment($fragment1, 1),
12-
api_static_fragment($fragment2, 3),
13-
api_static_fragment($fragment3, 5),
14-
api_static_fragment($fragment4, 7),
14+
api_element("iframe", stc0, [
15+
api_text("Hello <div>world</div> <div>foo</div>"),
16+
]),
17+
api_static_fragment($fragment2, 4),
18+
api_static_fragment($fragment3, 6),
1519
];
1620
/*LWC compiler vX.X.X*/
1721
}

packages/@lwc/template-compiler/src/codegen/static-element.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ function isStaticNode(node: BaseElement, apiVersion: APIVersion): boolean {
6161
// it is an element
6262
result &&= isElement(node);
6363

64+
// See W-17015807
65+
result &&= node.name !== 'iframe';
66+
6467
// all attrs are static-safe
6568
// the criteria to determine safety can be found in computeAttrValue
6669
result &&= attributes.every(({ name }) => {

0 commit comments

Comments
 (0)