Skip to content

Commit 33d0fc4

Browse files
committed
fix: form does not load after DomCententLoaded event has been fired
1 parent f8b6414 commit 33d0fc4

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/lib/js/common/utils/index.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,6 @@ export function parseData(data = Object.create(null)) {
339339

340340
return data
341341
}
342+
343+
344+
export const cleanFormData = formData => (formData ? clone(parseData(formData)) : {})

src/lib/js/editor.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Controls from './components/controls/index.js'
88
import Components from './components/index.js'
99
import { loadPolyfills, fetchIcons, fetchFormeoStyle } from './common/loaders.js'
1010
import { SESSION_LOCALE_KEY } from './constants.js'
11-
import { merge } from './common/utils/index.mjs'
11+
import { cleanFormData, merge } from './common/utils/index.mjs'
1212
import { defaults } from './config.js'
1313

1414
/**
@@ -32,7 +32,7 @@ export class FormeoEditor {
3232
dom.setOptions = opts
3333
Components.config = config
3434

35-
this.userFormData = userFormData || formData
35+
this.userFormData = cleanFormData(userFormData || formData)
3636

3737
this.Components = Components
3838
this.dom = dom
@@ -41,7 +41,11 @@ export class FormeoEditor {
4141
this.tooltip = new SmartTooltip()
4242

4343
// Load remote resources such as css and svg sprite
44-
document.addEventListener('DOMContentLoaded', this.loadResources.bind(this))
44+
if (document.readyState === 'loading') {
45+
document.addEventListener('DOMContentLoaded', this.loadResources.bind(this))
46+
} else {
47+
this.loadResources()
48+
}
4549
}
4650

4751
get formData() {

src/lib/js/renderer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import isEqual from 'lodash/isEqual'
22
import dom from './common/dom'
3-
import { uuid, isAddress, isExternalAddress, merge, parseData, clone } from './common/utils/index.mjs'
3+
import { uuid, isAddress, isExternalAddress, merge, cleanFormData } from './common/utils/index.mjs'
44
import { STAGE_CLASSNAME, UUID_REGEXP } from './constants'
55
import { fetchDependencies } from './common/loaders'
66

77
const RENDER_PREFIX = 'f-'
88

9-
const cleanFormData = formData => (formData ? clone(parseData(formData)) : {})
109
const containerLookup = container => (typeof container === 'string' ? document.querySelector(container) : container)
1110
const processOptions = ({ editorContainer, renderContainer, formData, ...opts }) => {
1211
const processedOptions = {

0 commit comments

Comments
 (0)