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

Do you support Nextjs and SWC? #171

Open
givo opened this issue Jun 16, 2024 · 6 comments
Open

Do you support Nextjs and SWC? #171

givo opened this issue Jun 16, 2024 · 6 comments

Comments

@givo
Copy link

givo commented Jun 16, 2024

Hey zthxxx!

First, thank you for the fantastic tool! It has been incredibly useful in my projects.

I'm currently working on a Next.js project that uses SWC for compiling - https://github.com/vercel/next-learn/tree/main/dashboard/final-example, and I've been trying to get react-dev-inspector to work with it. The extension works well with most frameworks, but I'm facing issues when trying to use it with Next.js, especially with server-side components.

I don't want to use babel like in your example in https://github.com/zthxxx/react-dev-inspector/tree/dev/examples/nextjs-custom-server because SWC is much faster but I also afraid that nextjs won't support babel for much longer.

I tried many things to make it work, like configuring next.config.js and .swcrc but nothing worked. Nothing seems to make nextjs + SWC to expose _debugInfo that your extension needs.

.swcrc:

{
  "jsc": {
    "target": "es2021",
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "transform": {
      "react": {
        "runtime": "automatic",
        "development": true,
        "refresh": true
      }
    }
  },
  "sourceMaps": true,
  "minify": false
}

next.config.js:

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack(config, { dev }) {
    config.mode = 'development';
    config.devtool = 'source-map';        // nextjs automatically converts this to eval-source-map
    return config;
  },
  reactStrictMode: true,
  swcMinify: false,
  productionBrowserSourceMaps: true,
};
module.exports = nextConfig;
  • Do you support nextjs with SWC?
  • Is it even possible to get source code of SSR components?

tnx

@zthxxx
Copy link
Owner

zthxxx commented Jun 19, 2024

It supports Next.js with SWC. Configs like your .swcrc are fine. (example in Next.js demo has enabled forceSwcTransforms)

But I haven’t tested server-side components yet. Currently, I think it wrong with supporting server-side components due to Next.js don't eject jsx-source for server-side components for hydrate.

@givo
Copy link
Author

givo commented Jun 19, 2024

Ok, so I tried adding forceSwcTransforms like this:

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack(config, { dev }) {
    config.mode = 'development';
    config.devtool = 'source-map'; // nextjs automatically converts this to eval-source-map
    return config;
  },
  reactStrictMode: true,
  swcMinify: false,
  productionBrowserSourceMaps: true,
  experimental: {
    forceSwcTransforms: true,
  },
};

module.exports = nextConfig;

It didn't work. I also don't see _debugInfo in client side components

@zthxxx
Copy link
Owner

zthxxx commented Jun 19, 2024

@givo
Copy link
Author

givo commented Jun 20, 2024

So I've set forceSwcTransforms: true in the nextjs dashboard project and this is what I get on a client side component:

image

There are very few client side component in this project, and in addition, when I inspect a client side component I only get the line of the component function like the following:

24 export default function NavLinks() {
25   const pathname = usePathname();
26
27   return (
28     <>
29       {links.map((link) => {
30         const LinkIcon = link.icon;
31          return (
  • I don't get the line number of the inspected HTML element like in your example.
  • By the way, I still don't see _debugInfo or _debugSource in fiber nodes

@zthxxx
Copy link
Owner

zthxxx commented Jul 6, 2024

I think here is the source code position of your react tsx file. (but I don't know what the ?55e5 is)

image

@tianyingchun
Copy link

it this support app-router for next.js?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants