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

[BUG] I cannot extract-meta of react functional-component, due to empty valueDeclaration. #2095

Closed
junbyeol opened this issue Jun 14, 2022 · 1 comment · Fixed by #2097
Closed

Comments

@junbyeol
Copy link

  • replace the result of pip list | grep dash below
dash                 2.5.0
dash-core-components 2.0.0
dash-html-components 2.0.0
dash-table           5.0.0

Describe the bug

I cannot extract meta of react functional-component, while class component works well.

 const ExternalShortcut: React.FC<Props> = () => {
   return <div>example</div>
 }; // It doesn't work..

//...

class ExternalShortcut extends React.Component<Props, any> {
  render() {
   return <div>example</div>;
  }
} // It works!

dash/extract-meta.js throws the error.

if (commentSource.valueDeclaration) {
                              ^

TypeError: Cannot read properties of undefined (reading 'valueDeclaration')
    at /Users/devsisters/Development/dashapp-poc-dashboard/src/components/lnb/venv/lib/python3.9/site-packages/dash/extract-meta.js:694:31
    at Array.forEach (<anonymous>)
    at /Users/devsisters/Development/dashapp-poc-dashboard/src/components/lnb/venv/lib/python3.9/site-packages/dash/extract-meta.js:645:17
    at Array.forEach (<anonymous>)
    at gatherComponents (/Users/devsisters/Development/dashapp-poc-dashboard/src/components/lnb/venv/lib/python3.9/site-packages/dash/extract-meta.js:640:33)
    at Object.<anonymous> (/Users/devsisters/Development/dashapp-poc-dashboard/src/components/lnb/venv/lib/python3.9/site-packages/dash/extract-meta.js:754:18)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)

This is how I fixed.

// Function components.
                    rootExp = typeSymbol;
//                    rootExp.valueDeclaration = rootExp.declarations[0]; // This line is what I add. This line makes the build of functional component success.
                    commentSource = rootExp.valueDeclaration;
                    if (
                        rootExp.valueDeclaration &&
                        rootExp.valueDeclaration.parent
                    ) {
                        // Function with export later like `const MyComponent = (props) => <></>;`
                        commentSource = getParent(
                            rootExp.valueDeclaration.parent
                        );
                    }

Expected behavior

I expected to extract-meta.js work well for react functional-component.

@T4rk1n
Copy link
Contributor

T4rk1n commented Jun 14, 2022

There is two bug here:

  • React.FC<Props> throws the above error
  • a function component cannot have empty props but that should be valid (eg; const Component = () => <div>foo</div>) throws:Uncaught TypeError: Cannot convert undefined or null to object

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