Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throws undefined errors when using Gatsby #29

Closed
1 of 4 tasks
gigaSproule opened this issue Sep 20, 2021 · 4 comments
Closed
1 of 4 tasks

Throws undefined errors when using Gatsby #29

gigaSproule opened this issue Sep 20, 2021 · 4 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@gigaSproule
Copy link
Contributor

gigaSproule commented Sep 20, 2021

  • I'm submitting a ...

  • bug report

  • feature request

  • question about the decisions made in the repository

  • question about how to use this project

  • Summary

When using this library with GatsbyJS, depending on what's included in the page, will cause undefined errors to be thrown. The reason for this is because the library loads the script in asynchronously and because it's to the body. This is because with Gatsby, it is rendering the page server side, setting the state as loaded, then when the page is actually loaded into the browser, it is passing the "loaded" check before it's actually been loaded.

If there was an option to load this synchronously and to add the script to the head (as it supposedly should do as per comment https://github.com/aaronhayes/react-use-hubspot-form/blob/master/src/HubspotProvider.tsx#L17), then this will no longer be an issue.

A simple example to replicate this behaviour:

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<script>
  hbspt.forms.create({
    region: region,
    portalId: portalId,
    formId: formId
  });
</script>
</script>
<script charset="utf-8" type="text/javascript" src="https://js.hsforms.net/forms/v2.js"></script>
</body>
</html>
@aaronhayes aaronhayes added bug Something isn't working help wanted Extra attention is needed labels Sep 21, 2021
@aaronhayes
Copy link
Owner

Makes sense, happy to accept PRs for this

@gigaSproule
Copy link
Contributor Author

I was planning to do one last night, but didn't get time to. I will try and get one over today.

@gigaSproule
Copy link
Contributor Author

I hope the PR is adequate. I've made it so there are no backwards breaking changes, so existing users won't get any errors when upgrading.

@aaronhayes
Copy link
Owner

Thanks @gigaSproule appreciated it. Released in 2.1.0 by #30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants