question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deprecation warnings for non-Gatsby code

See original GitHub issue

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 

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
robinmetralcommented, Jan 10, 2020

@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).

1reaction
sidharthachatterjeecommented, Jan 10, 2020

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Complete Guide for Deprecation Warnings in Rails
After you fix a deprecation warning in the project, you want to make sure that nobody introduces that deprecated code again. Rubocop. If...
Read more >
Dealing with Deprecation Warnings - Java Cookbook [Book]
Your code used to compile cleanly, but now gives deprecation warnings. Solution. You must have blinked :-). Either live with the warnings --...
Read more >
warnings — Warning control — Python 3.11.1 documentation
Base category for warnings about deprecated features when those warnings are intended for other Python developers (ignored by default, unless triggered by code...
Read more >
How to ignore deprecation warnings in Python - Stack Overflow
You should just fix your code but just in case, import warnings warnings.filterwarnings("ignore", category=DeprecationWarning).
Read more >
Deprecation warnings in Python code - Piccolo Blog
Deprecation warnings in Python code. When working on Python libraries like Piccolo, it's important to evolve it in a graceful way.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found