Gatsby: Deprecation warnings for non-Gatsby code

Created on 7 Jan 2020  ·  4Comments  ·  Source: gatsbyjs/gatsby

Description

On develop, Gatsby parses the codebase for deprecated APIs like pathContext and boundActionsCreator. In some cases, these keywords are detected in non-Gatsby code, as mentioned already in #11679 (closed) and #10211 (stale), and a warning is shown:

pathContext is deprecated
_Real example of the warning being thrown for minified Storybook code_

Steps to reproduce

  1. gatsby new bug-repro https://github.com/gatsbyjs/gatsby-starter-hello-world
  2. cd bug-repro
  3. mkdir random-files && echo pathContext > random-files/random-file.js
    ➡️ this creates a js file and writes pathContext in it
  4. gatsby develop

Expected result

These warnings should only be shown if these deprecated APIs are actually being used in the Gatsby project.

Actual result

pathContext is deprecated

Environment

  System:
    OS: macOS 10.15.2
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.6.0 - ~/.nvm/versions/node/v12.6.0/bin/node
    Yarn: 1.19.1 - ~/.yarn/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v12.6.0/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 79.0.3945.88
    Firefox: 71.0
    Safari: 13.0.4
  npmPackages:
    gatsby: ^2.18.12 => 2.18.12 
help wanted not stale reporter maintenance

All 4 comments

Love detailed issues like these. Thanks @robinmetral 🙌

So the deprecation warning here isn't for APIs in non-Gatsby code but for instances of pathContext and boundActionsCreator in _any_ code because they are available as props and could be passed down arbitrarily.

The heuristic isn't great though and we should improve this since it is confusing.

Perhaps we can lint for if they are props and then print this warning? What do you think?

@sidharthachatterjee checking if they are props before printing the warning could work! Not sure how we could lint this though, any ideas? 🤔

I had another related idea - could we somehow stop Gatsby from parsing files that are ignored in .gitignore (or .gatsbyignore 😛)? In my case for instance, the storybook-public folder is ignored, similarly to Gatsby's public folder. This is where keywords like boundActionsCreator come up unexpectedly.

If Gatsby took an ignore file as a CLI flag or a config option, we could avoid some warnings. There's probably already some ignore logic built in, to avoid parsing node_modules for instance. This could ensure that warnings are only thrown for code that is actually intended to be in the Gatsby project (i.e. not ignored).

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/contribute for more information about opening PRs, triaging issues, and contributing!

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

Can confirm, the warning occurs with the latest versions of gatsby and storybook:

pathContext is deprecated. Please use pageContext instead. For migration instructions, see https://gatsby.dev/pathContext
Check the following files:
⠀
storybook-static/vendors~main.25ccc0c30aa0c97984ed.bundle.js

I like the .gitignore idea

Was this page helpful?
0 / 5 - 0 ratings

Related issues

magicly picture magicly  ·  3Comments

signalwerk picture signalwerk  ·  3Comments

ghost picture ghost  ·  3Comments

ferMartz picture ferMartz  ·  3Comments

benstr picture benstr  ·  3Comments