Skip to content

Commit

Permalink
Merge pull request #780 from newrelic/zack/firefox-crash-fix
Browse files Browse the repository at this point in the history
Fix Firefox crash (marketo forms)
  • Loading branch information
zstix authored Sep 23, 2020
2 parents 7e03719 + 2f9bfbe commit de7b44e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
10 changes: 6 additions & 4 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ const onInitialClientRender = () => {
}
}

// eslint-disable-next-line no-undef
MktoForms2.whenRendered(function (form) {
destyleMktoForm(form);
});
if (typeof window !== 'undefined' && window.MktoForms2) {
// eslint-disable-next-line no-undef
MktoForms2.whenRendered(function (form) {
destyleMktoForm(form);
});
}
};

const onRouteUpdate = ({ location }) => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/MarketoForm/MarketoForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const MarketoForm = ({
publishableKey,
redirectLink,
}) => {
useMarketoForm(munchkinId, id, publishableKey, redirectLink);
const loaded = useMarketoForm(munchkinId, id, publishableKey, redirectLink);

return (
return loaded ? (
<div
css={css`
position: relative;
Expand All @@ -40,7 +40,7 @@ const MarketoForm = ({
<form id={`mktoForm_${id}`} />
</div>
</div>
);
) : null;
};

MarketoForm.propTypes = {
Expand Down
11 changes: 10 additions & 1 deletion src/hooks/useMarketoForm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { useEffect } from 'react';
import { useEffect, useState } from 'react';
import { navigate } from 'gatsby';

const useMarketoForm = (munchkinId, id, publishableKey, redirectLink) => {
const [loaded, setLoaded] = useState(false);

useEffect(() => {
if (!window.MktoForms2) {
return;
}
setLoaded(true);

window.MktoForms2.loadForm(
'//app-abj.marketo.com',
munchkinId,
Expand Down Expand Up @@ -43,6 +50,8 @@ const useMarketoForm = (munchkinId, id, publishableKey, redirectLink) => {
};
document.body.append(script);
}, [munchkinId, id, publishableKey, redirectLink]);

return loaded;
};

export default useMarketoForm;

0 comments on commit de7b44e

Please sign in to comment.