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

Add displayName to Loadable and WithChunkExtractor based components #727

Closed
forivall opened this issue Mar 29, 2021 · 2 comments · Fixed by #731
Closed

Add displayName to Loadable and WithChunkExtractor based components #727

forivall opened this issue Mar 29, 2021 · 2 comments · Fixed by #731

Comments

@forivall
Copy link
Contributor

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @loadable/component@5.14.1 for the project I'm working on.

Basically, I added displayNames to the generated loadable components, so that they are identifiable in react-devtools. If this change would be acceptable, i'll convert this into a PR

Here is the diff that solved my problem:

diff --git a/node_modules/@loadable/component/dist/loadable.esm.js b/node_modules/@loadable/component/dist/loadable.esm.js
index 7f43596..80f589d 100644
--- a/node_modules/@loadable/component/dist/loadable.esm.js
+++ b/node_modules/@loadable/component/dist/loadable.esm.js
@@ -59,13 +59,17 @@ function resolveConstructor(ctor) {
 }
 
 var withChunkExtractor = function withChunkExtractor(Component) {
-  return function (props) {
+  function LoadableWithChunkExtractor(props) {
     return React.createElement(Context.Consumer, null, function (extractor) {
       return React.createElement(Component, Object.assign({
         __chunkExtractor: extractor
       }, props));
     });
   };
+  if (Component.displayName) {
+    LoadableWithChunkExtractor.displayName = Component.displayName + 'WithChunkExtractor';
+  }
+  return LoadableWithChunkExtractor;
 };
 
 var identity = function identity(v) {
@@ -395,6 +399,8 @@ function createLoadable(_ref) {
       }, props));
     }); // In future, preload could use `<link rel="preload">`
 
+    Loadable.displayName = 'Loadable';
+
     Loadable.preload = function (props) {
       ctor.requireAsync(props);
     };

This issue body was partially generated by patch-package.

obvi, the patch is to the esm build, so my PR would be editing the source.

@open-collective-bot
Copy link

Hey @forivall 👋,
Thank you for opening an issue. We'll get back to you as soon as we can.
Please, consider supporting us on Open Collective. We give a special attention to issues opened by backers.
If you use Loadable at work, you can also ask your company to sponsor us ❤️.

@theKashey
Copy link
Collaborator

❤️ patch-package :)

The change is more than acceptable, feel free to open a PR

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

Successfully merging a pull request may close this issue.

2 participants