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

[core] Fix thrown error during eval phase #196

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

brijeshb42
Copy link
Contributor

@brijeshb42 brijeshb42 commented Aug 7, 2024

This PR changes the way we throw errors for our top-level exported functions. With the introduction of our build-time container components, we also started using the top-level APIs in these components. This in itself is ok since we don't want any restrictions. But this lead to an issue where an error was thrown, typically if trying to add sx prop on such container components (1 example).
This was because these container component files were also being evaluated during the eval phase of wyw and that phase also included calls to generateAtomics which always throws error. So with this change, we first detect whether the function is being called during the eval phase or not, by checking a special global variable called __wyw_dynamic_import which is set by WyW before evaluation happens. So now these functions don't throw error during the eval stage.

Fixes #193

This change changes the way we throw errors for our top-level exported
functions. With the introduction of our build-time container components,
we also started using the top-level APIs in these components. This in
itself is ok since we don't want any restrictions. But this lead to an
issue where an error was thrown, typically if trying to add sx prop on
such container components (1 example).
This was because these container component files were also being
evaluated during the eval phase of wyw and that phase also included
calls to generateAtomics which always throws error.
So with this change, we first detect whether the function is being
called during the eval phase or not, by checking a special global
variable called `__wyw_dynamic_import` which is set by WyW before
evaluation happens. So now these functions don't throw error during the
eval stage.
@brijeshb42 brijeshb42 added bug 🐛 Something doesn't work component: Grid The React component. labels Aug 7, 2024
Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation!

@brijeshb42 brijeshb42 merged commit 794b443 into mui:master Aug 7, 2024
13 of 14 checks passed
@brijeshb42 brijeshb42 deleted the fix/grid-eval branch August 28, 2024 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: Grid The React component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[nextjs] Cannot use sx prop on layout components
2 participants