-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
createMuiTheme overrides not working since 4.9.6 #23739
Comments
I'm not sure we want to support this multi-frame case with the theme. How did you encounter this situation? |
Before all, thanks for your fast reply! I understand that edge cases do not justify increasing bundle size 👍. I've created a PR just to show the case, the goal was not really o be merged ;) (the isPlainObject code is borrowed from lodash).
In my current case, I CAN NOT upgrade material-ui up to 4.9.5 for now. |
We support it everywhere else. Why change it in this particular instance? That sounds way to confusing for library users unless you are familiar with the implementation of the library which defeats the purpose of using a library.
@fbaeta Could you open a PR that replaces internal usage with this library instead? It's apparent that this kind of functionality needs to be checked in a dedicated package. Current implementation shows a type of hubris that you usually find in people not familiar with the JS ecosystem: "just write your own. how hard can it be?". Well, we had two bugs now in code we wrote that we could've easily imported instead. That would have saved us time. Instead of sinking more time into the problem we should be able to recognize sunk-cost fallacy. |
@eps1lon I'm asking because it doesn't seem to be something we fundamentally prevent from supporting. As far as I know, It's not blocking. Developers can bypass the We know that multi-frame support is rarely used but we still support it. I suspect this specific case is unique and nonblocking. A drop in the bucket most developers would rather have us ignore (not pay the cost for it). Not every bug deserved to be fixed. I think that it's a big factor in the "write your own" popularity, it allows different tradeoffs (but also come with ignoring problems you don't know you have). |
@fbaeta Feel free to provide a reproduction. If there are no workarounds, we should probably consider a solution in Material-UI. However, you are mentioning the theme creator helper that can be bypassed, so we would very likely be better off ignoring this problem. We can also reconsider if more developers face this issue. |
I will give you a more isolated case of the use case that we are facing in some weeks. You mention that theme creator can be bypassed. How? The theme creator is a feature of MUI, we are happy with it and we want to continue to use it. Nevertheless,
|
@fbaeta Thanks! Do you have a specific use case for providing an element from a different window inside the theme?
MUI is, you can bypass |
We've hit this issue in Toolpad. See mui/toolpad#2514. We have a workaround, but I believe it would be better if MUI core provided a more defensive |
Based on sindresorhus/is-plain-obj#11, this could fix it: diff --git a/packages/mui-utils/src/deepmerge.test.ts b/packages/mui-utils/src/deepmerge.test.ts
index d0aceef896..641672c613 100644
--- a/packages/mui-utils/src/deepmerge.test.ts
+++ b/packages/mui-utils/src/deepmerge.test.ts
@@ -1,3 +1,4 @@
+import { runInNewContext } from 'vm';
import { expect } from 'chai';
import deepmerge from './deepmerge';
@@ -60,4 +61,13 @@ describe('deepmerge', () => {
expect(result).to.deep.equal({ foo: { baz: 'new test' } });
expect(foo).to.deep.equal({ foo: { baz: 'test' } });
});
+
+ it('should deep clone with object of different realm', () => {
+ const foo = { foo: { baz: 'test' } };
+ const bar = runInNewContext('({})');
+
+ const result = deepmerge(bar, foo);
+
+ expect(result).to.deep.equal({ foo: { baz: 'test' } });
+ });
});
diff --git a/packages/mui-utils/src/deepmerge.ts b/packages/mui-utils/src/deepmerge.ts
index 1d0c9a44b8..883f01e417 100644
--- a/packages/mui-utils/src/deepmerge.ts
+++ b/packages/mui-utils/src/deepmerge.ts
@@ -1,5 +1,11 @@
export function isPlainObject(item: unknown): item is Record<keyof any, unknown> {
- return item !== null && typeof item === 'object' && item.constructor === Object;
+ // Basic check
+ if (item == null || typeof item !== 'object') {
+ return false;
+ }
+
+ const prototype = Object.getPrototypeOf(item);
+ return prototype === null || Object.getPrototypeOf(prototype) === null;
}
export interface DeepmergeOptions { https://stackoverflow.com/questions/49832187/how-to-understand-js-realms explains a bit why this could be valuable. Why not. |
createMuiTheme(a, b)
overrides not working since 4.9.6Since #20095 & #20100, the isPlainObject has been modified.
material-ui/packages/mui-utils/src/deepmerge.ts
Lines 1 to 3 in b935d3e
Testing
constructor
property is not multi-frame proof.This makes
deepmerge
do not merge incoming properties from a givensource
whensource
is an Object created in another js context like another document iframe.Current Behavior 😯
The generated jss style does not conatin overrides, so desired style is not applied to components.
Expected Behavior 🤔
The generated jss style must contain overrides in order to have the desired styles applied to components.
The text was updated successfully, but these errors were encountered: