Skip to content

Commit a781a94

Browse files
author
Matej Lednicky
committed
fix(DIST-629): Update iframe reload logic
When widget is opened as popup on mobile the iframe needs to be reloaded to make sure we display welcome screen again after the popup is closed. Our current logic stopped working.
1 parent fde02d2 commit a781a94

File tree

6 files changed

+31
-24
lines changed

6 files changed

+31
-24
lines changed

demo/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ <h2>Embed snippet</h2>
1717
<li><a href="./widget-transparent.html">Widget with trasnparent background *</a></li>
1818
<li><a href="./widget-legacy.html">Widget with legacy hidden fields *</a></li>
1919
<li><a href="./widget-v2.html">Widget with long text</a></li>
20+
<li><a href="./widget-real.html">Widget (real world typeform)</a></li>
2021
<li><a href="./multi-widget.html">Multiple widgets</a></li>
2122
<li><a href="./full.html">Full page *</a></li>
2223
<li><a href="./popup.html">Popups *</a></li>

demo/widget-real.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Widget (real typeform)</title>
5+
<meta charset="utf-8" />
6+
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
7+
<link rel="stylesheet" href="demo.css" />
8+
</head>
9+
<body>
10+
<div
11+
class="typeform-widget"
12+
data-url="https://form.typeform.com/to/jAJ5qj#foo=random internet user"
13+
style="width: 100%; height: 500px"
14+
></div>
15+
16+
<script type="text/javascript" src="embed.js"></script>
17+
</body>
18+
</html>

src/core/make-widget.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ export default function makeWidget(element, url, options) {
4848
let queryStrings = replaceExistingKeys(options, queryStringKeys)
4949
queryStrings = transferUrlParametersToQueryStrings(options.transferableUrlParameters, queryStrings)
5050

51-
if (enabledFullscreen) {
52-
queryStrings = {
53-
...queryStrings,
54-
'add-placeholder-ws': true,
55-
}
56-
}
57-
5851
const urlWithQueryString = appendParamsToUrl(url, queryStrings)
5952

6053
render(

src/core/make-widget.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ describe('makeWidget', () => {
6262

6363
const widgetURL = component.props.url
6464
const { query } = UrlParse(widgetURL, true)
65-
expect(query['add-placeholder-ws']).toBe('true')
6665
expect(query['mandarina']).toBeUndefined()
6766

6867
expect(component.type.name).toEqual('Widget')

src/core/views/widget.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,11 @@ const PlaceholderAnimationAppear = keyframes`
5757
`
5858

5959
const PlaceholderAnimationDisappear = keyframes`
60-
100% {
61-
opacity: 0;
62-
}
63-
64-
75% {
65-
opacity: 1;
66-
}
67-
68-
69-
25% {
60+
0% {
7061
opacity: 1;
7162
}
72-
73-
0% {
63+
64+
100% {
7465
opacity: 0;
7566
}
7667
`
@@ -176,7 +167,7 @@ class Widget extends Component {
176167
goFullScreen() {
177168
if (this.props.enabledFullscreen) {
178169
this.setState({ isFullscreen: true })
179-
setTimeout(this.reloadIframe, 500)
170+
this.reloadIframe()
180171
}
181172
}
182173

@@ -226,8 +217,11 @@ class Widget extends Component {
226217

227218
reloadIframe() {
228219
// Re-assign the source of the iframe, makes it reload cross-browser
229-
// eslint-disable-next-line
230-
this.iframe.iframeRef.src = this.iframe.iframeRef.src
220+
const originalSrc = this.iframe.iframeRef.src
221+
this.iframe.iframeRef.src = ''
222+
setTimeout(() => {
223+
this.iframe.iframeRef.src = originalSrc
224+
}, 250)
231225
}
232226

233227
focusIframe() {
@@ -266,6 +260,7 @@ class Widget extends Component {
266260

267261
if (enabledFullscreen) {
268262
inlineIframeUrl = updateQueryStringParameter('disable-tracking', 'true', inlineIframeUrl)
263+
inlineIframeUrl = updateQueryStringParameter('add-placeholder-ws', 'true', inlineIframeUrl)
269264
}
270265

271266
let fullscreenIframeUrl = updateQueryStringParameter('typeform-welcome', '0', url)

src/core/views/widget.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ describe('Widget', () => {
7878
expect(onSubmitMock).toHaveBeenCalledTimes(1)
7979
})
8080

81-
it('renders an iframe with disabled submissions', () => {
81+
it('renders an iframe with disabled submissions and placeholder welcome screen', () => {
8282
const wrapper = mount(<Widget enabledFullscreen url={URL} />)
8383
expect(wrapper.find(Iframe)).toHaveLength(1)
8484
expect(wrapper.find(Iframe).props().src.includes('disable-tracking=true')).toBe(true)
85+
expect(wrapper.find(Iframe).props().src.includes('add-placeholder-ws=true')).toBe(true)
8586
})
8687

8788
it('renders a second iframe after the welcome-screen-hidden event', () => {

0 commit comments

Comments
 (0)