From 63c6f60360992fb07d358c5172f708bf2877cba7 Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Wed, 5 Jun 2019 18:28:19 -0400 Subject: [PATCH] chore(docs): Add content for "client side only packages" (#14211) * Add stub for client side only components This stub comes from a tip I came across here: https://github.com/gatsbyjs/gatsby/issues/13355#issuecomment-483265025 * prettier fixes * prettier code style fixes * Update docs/docs/using-client-side-only-libraries.md Co-Authored-By: Marcy Sutton * Update docs/docs/using-client-side-only-libraries.md Co-Authored-By: Marcy Sutton * Update docs/docs/using-client-side-only-libraries.md Co-Authored-By: Marcy Sutton * remove stub and add call for contribution * add clarifying comments * add to doc-links -> Adding Website Functionality * rename file to match title * point to docs on Debugging HTML Builds * Workaround 2, the react way read more here: https://reactjs.org/docs/integrating-with-other-libraries.html#integrating-with-dom-manipulation-plugins * update to use loadable-components --- docs/docs/using-client-side-only-packages.md | 85 ++++++++++++++++++++ www/src/data/sidebars/doc-links.yaml | 2 + 2 files changed, 87 insertions(+) create mode 100644 docs/docs/using-client-side-only-packages.md diff --git a/docs/docs/using-client-side-only-packages.md b/docs/docs/using-client-side-only-packages.md new file mode 100644 index 0000000000000..464c918b3483d --- /dev/null +++ b/docs/docs/using-client-side-only-packages.md @@ -0,0 +1,85 @@ +--- +title: Using Client-Side Only Packages +--- + +On occasion, you may need to use a function or library that only works client side. This usually is because the library in question accesses something that isn't available during server-side rendering (SSR), like [browser DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model) methods. + +You'll need to use one of the workarounds outlined below if your project fails to compile with `gatsby develop` or `gatsby build` with an error like: + +```bash +Reference error: Window is not Defined +``` + +## Workaround 1: Use a different library or approach + +Sometimes the simplest approach is to work around the problem. If you can re-implement your component using a plugin which _doesn't_ break SSR, that's probably best. + +## Workaround 2: Add client-side package via CDN + +In the component where you need it, load the package via CDN using a [`