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.

[gatsby-plugin-mdx] MDXRenderer creates "Unreachable code after return statement" warning in firefox console

See original GitHub issue

Description

When using MDXRenderer from gatsby-plugin-mdx, firefox throws a warning in Firefox, both in develop and production.

import React from 'react';
import { graphql } from 'gatsby';
import MDXRenderer from 'gatsby-plugin-mdx/mdx-renderer';

export default function Post({ data: { mdx } }) {
  return <MDXRenderer>{mdx.body}</MDXRenderer>;
}

export const pageQuery = graphql`
  query($id: String!) {
    mdx(fields: { id: { eq: $id } }) {
      body
    }
  }
`;

This results in the following warning in Firefox console:

unreachable code after return statement

Steps to reproduce

I created this mdx blog starter to reproduce.

It is deployed to netlify where you can see the error, or run it locally:

* `gatsby new gatsby-mdx-blog-starter-project git@github.com:danieltott/gatsby-mdx-blog-starter-project.git`
* `cd gatsby-mdx-blog-starter-project`
* `gatsby develop`
* In Firefox, visit http://localhost:8000/graphql-book

At this point, If you go to http://localhost:8000/graphql-book, you’ll get an error in the console on Firefox (and Firefox Developer Edition) unreachable code after return statement with a link to the MDN docs.

Expected result

I would expect this to run without a warning.

Actual result

I get the warning in firefox.

Environment

gatsby info --clipboard

  System:
    OS: macOS 10.15.4
    CPU: (4) x64 Intel(R) Core(TM) i7-6567U CPU @ 3.30GHz
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.8.1 - ~/.nvm/versions/node/v12.8.1/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.10.2 - ~/.nvm/vers

More info/thoughts

If you console.log the contents of mdx.body, you can clearly see the MDXContent.isMDXComponent = true; statement after return function MDXContent:

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

/* @jsx mdx */
var _frontmatter = {
  "slug": "/graphql-book",
  "date": "2018-07-18T13:35:13.234Z",
  "title": "The Road to GraphQL",
  "description": "GraphQL Description ...",
  "categories": ["graphql", "javascript"],
  "keywords": ["graphql", "book"],
  "banner": "./images/banner.jpg"
};

var makeShortcode = function makeShortcode(name) {
  return function MDXDefaultShortcode(props) {
    console.warn("Component " + name + " was not imported, exported, or provided by MDXProvider as global scope");
    return mdx("div", props);
  };
};

var Link = makeShortcode("Link");
var layoutProps = {
  _frontmatter: _frontmatter
};
var MDXLayout = "wrapper";
return function MDXContent(_ref) {
  var components = _ref.components,
      props = _objectWithoutProperties(_ref, ["components"]);

  return mdx(MDXLayout, _extends({}, layoutProps, props, {
    components: components,
    mdxType: "MDXLayout"
  }), mdx("p", null, "clipped for brevity."), mdx(Link, {
    to: "https://roadtoreact.com/",
    mdxType: "Link"
  }, "Find out more about it"), mdx("p", null, "clipped for brevity."), mdx("p", null, "clipped for brevity."));
}
;
MDXContent.isMDXComponent = true;

This is originally coming from mdx-js/react, mdx-js creates JSX. Somehow, somewhere, this is getting transformed into regular js.

So, this may belong in a different repo, but I don’t have any idea where it would be if it’s not here.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
wardpeetcommented, Apr 17, 2020

@danieltott Thanks for creating this issue. This seems indeed odd. I’ll let the mdx folks know and see what they say.

1reaction
Glazycommented, Dec 3, 2021

Related to #34191 which contains a minimal reproduction of this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning: unreachable code after return statement - JavaScript
When an expression exists after a valid return statement, a warning is given to indicate that the code after the return statement is...
Read more >
Why is `unreachable code after return statement` warning ...
When loading test.html the console shows the unreachable code after return statement warning twice now. The return is in a switch-case ...
Read more >
Warning: unreachable code after return statement - JavaScript
When an expression exists after a valid return statement, a warning is given to indicate that the code after the return statement is...
Read more >
javascript Warning: unreachable code after return statement
Warning : unreachable code after return statement (Firefox). Error Type. Warning. What went wrong? Unreachable code after a return statement might occur in ......
Read more >
gatsby-mdx-blog-starter-project: A JavaScript repository from ...
Reduced test case for Gatsby issue. Issue: [gatsby-plugin-mdx] MDXRenderer creates "Unreachable code after return statement" warning in firefox console ...
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