welldone-software / why-did-you-render

why-did-you-render by Welldone Software monkey patches React to notify you about potentially avoidable re-renders. (Works with React Native as well.)
https://www.npmjs.com/package/@welldone-software/why-did-you-render
MIT License
11.2k stars 201 forks source link

Issues with Parcel? #267

Closed wpcarro closed 1 year ago

wpcarro commented 1 year ago

Anyone else having issues with Parcel? I'm not seeing any logs, and I've followed the Troubleshooting guide. Here's my setup:

// wdyr.js
import React from 'react';

if (process.env.NODE_ENV === 'development') {
    console.log('here');
    const wdyr = require('@welldone-software/why-did-you-render');
    wdyr(React, {
        trackAllPureComponents: true,
    });
}
// index.jsx
import "./wdyr.js";
import { createRoot } from "react-dom/client";
import React from "react";

const Table = ({ foo }) => (
  // omitted ...
);
Table.whyDidYouRender = true;

class App extends React.Component {
  static whyDidYouRender = true;
  // omitted ...
}

const container = document.getElementById("mount");
const root = createRoot(container);
root.render(<App />);
root.render(<App />); // 2x-times to force wdyr to detect something

What's the pebcak here?

wpcarro commented 1 year ago

I'm seeing here logged in the console fwiw

wpcarro commented 1 year ago

Serving the content with yarn parcel server --no-cache src/index.html

wpcarro commented 1 year ago

This worked for me (sorry for the noise):

module.exports = {
  presets: [
    [
      '@babel/preset-react',
      {
        runtime: 'automatic',
        development: process.env.NODE_ENV === 'development',
        importSource: '@welldone-software/why-did-you-render',
      },
    ],
  ],
};