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

Allow to pass functions in gatsby-config.js for browser and SSR #14199

Closed
mike1808 opened this issue May 21, 2019 · 4 comments
Closed

Allow to pass functions in gatsby-config.js for browser and SSR #14199

mike1808 opened this issue May 21, 2019 · 4 comments
Labels
stale? Issue that may be closed soon due to the original author not responding any more.

Comments

@mike1808
Copy link

Summary

Currently, options for the plugins in gatsby-config.js are stringified for the browser and SSR as mentioned in #13440 However, in some plugins functions are the part of the configurations. So preserving functions would be a great addition for the config file.'

Basic example

Imagine you have a plugin which calls your provided callback.

plugins: [
  { 
    resolve: 'gatsby-plugin-on-page-load',
    options: { onLoad() { sessionStorage.setItem('loaded', 'true'); }
  }
]

Motivation

In some plugins, you need to provide some kind of callback. I faced this issue with gatsby-plugin-web-font-loader where I needed to provide a callback for font load.

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Jun 11, 2019
@gatsbot
Copy link

gatsbot bot commented Jun 11, 2019

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contributefor more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@wardpeet
Copy link
Contributor

wardpeet commented Jun 12, 2019

This is a hard nut to crack at the moment. We have to send this function over to webpack which is a bit hard. We can stringify it but a better ways it to compile it to an AST and reconstruct it on gatsby-browser.

A workaround for this is to save this content to disk and import it inside gatsby-browser.

@joefiorini
Copy link
Contributor

I running into this issue as well. I'm using a gatsby theme and I have multiple sites. Each one needs to pass an object that is used for some central configuration, and that object can have functions (it's for mocking API endpoints client-side). In the theme's gatsby-browser I take the configuration object and pass it on to a provider component. At that point it's lost the functions :(. Note that I can't import this configuration in the theme's gatsby-browser or gatsby-ssr because it is unique for each gatsby site that uses the theme. I can't seem to find anywhere else I can pass it, unless I completely change my architecture and set it up using a hook, which doesn't sound very easy either.

@gatsbot
Copy link

gatsbot bot commented Jul 2, 2019

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.

Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more.
Projects
None yet
Development

No branches or pull requests

3 participants