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

The repo stylesheet 'resetting' my parent component's material-ui stylesheet in Nextjs application #101

Open
galliumsoft opened this issue Jul 28, 2021 · 16 comments
Labels
bug Something isn't working

Comments

@galliumsoft
Copy link

galliumsoft commented Jul 28, 2021

Hi,
I went through the codebase and was not able to identify the source of the issue and correct it if needed. I can do the change and send a PR if you can point me in the right direction.
The issue is that I have a component which has a material-ui stylesheet and am exploring the use of chonky for handling the files within it as a subcomponent. The component itself works fine etc. However, the problem is when i come into the chonky part of the component, the stylesheet of the entire parent gets reset to the chonky stylesheet. Is there anyway to avoid these global effects?
I suspect it is to do with the way createusestyles works in the react-jss component that is used in the styles.ts sheet. Any pointers on what can be done here? The issue probably is owing to the way react-jss behaves in nextjs application
cheers

@galliumsoft galliumsoft changed the title The repo stylesheet 'resetting' my parent component's material-ui stylesheet The repo stylesheet 'resetting' my parent component's material-ui stylesheet in Nextjs application Jul 28, 2021
@ArslanMustafin
Copy link

@galliumsoft. Hi, Have you found a solution to this problem?
Or maybe you can suggest a similar library alternative.

@aaraney
Copy link

aaraney commented Sep 9, 2021

@galliumsoft, @ArslanDev666, I've run into this same issue and may have come upon a solution?

In brief, I wrapped my application in a material-ui ThemeProviderwith the default theme and the sibling/parent elements are no longer being styled by styles defined in Chonky. See the below example.

// index.tsx

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { createTheme, ThemeProvider } from "@material-ui/core";

// material-ui default theme
const customTheme = createTheme({});

ReactDOM.render(
  <React.StrictMode>
    <ThemeProvider theme={customTheme}>
      <App />
    </ThemeProvider>
  </React.StrictMode>,
  document.getElementById("root")
);
// App.tsx

import React from "react";
import { AppBar, Container, Toolbar } from "@material-ui/core";
import {
  setChonkyDefaults,
  FileBrowser,
  FileData,
  FileList,
  FileNavbar,
  FileToolbar,
} from "chonky";
import { ChonkyIconFA } from "chonky-icon-fontawesome";

// Somewhere in your `index.ts`:
setChonkyDefaults({ iconComponent: ChonkyIconFA });

const files: FileData[] = [{ id: "1", name: "file" }];

function App() {
  return (
    <Container>
      <AppBar position="static">
        <Toolbar></Toolbar>
      </AppBar>
      <FileBrowser files={files}>
        <FileNavbar />
        <FileToolbar />
        <FileList />
      </FileBrowser>
    </Container>
  );
}

export default App;

I hope this helps!

@andvikt
Copy link

andvikt commented Nov 26, 2021

@galliumsoft, @ArslanDev666, I've run into this same issue and may have come upon a solution?

In brief, I wrapped my application in a material-ui ThemeProviderwith the default theme and the sibling/parent elements are no longer being styled by styles defined in Chonky. See the below example.

I hope this helps!

does not work

@marisaza
Copy link

marisaza commented Dec 2, 2021

In my case I have wrapped FileToolbar by ThemeProvider and it helps.

//Chonky v2.3.0
//...
import { ThemeProvider } from "@material-ui/core";

//...
  <FileBrowser
    /* ... */              
  >
    <FileNavbar />
    <ThemeProvider >
      <FileToolbar />
    </ThemeProvider>
    <FileList />
  </FileBrowser>

@marisaza
Copy link

Or better

//Chonky v2.3.0
//...
import { ThemeProvider } from "@material-ui/core";

//...
  <ThemeProvider >
    <FileBrowser
   /* ... */   
    >
      <FileNavbar />
      <FileToolbar />
      <FileList />
    </FileBrowser>
  </ThemeProvider>

@TimboKZ
Copy link
Owner

TimboKZ commented Jan 8, 2022

Thanks for figuring this out!

@TimboKZ TimboKZ added the bug Something isn't working label Jan 8, 2022
@weagertron
Copy link

Are there any updates on this at all? This fix does not seem to work with Mui v5 and I am struggling to find any other form of workaround

@aaraney
Copy link

aaraney commented Apr 12, 2022

@weagertron, chony uses @material-ui/core": "4.11.3". I think the best option right now is to use MUI v4.

@MSFTserver
Copy link

MSFTserver commented May 12, 2022

Im having a similar issue but it seems be overriding my gatsby-plugin-layout theming when they used to work together in chonky 2.0.1 but now my layout tags are broken and ive tried setting chonky and material UI back to old versions that did simehow work together in the past but are failing now.

the second image would be injected as a child
Screenshot_20220511-230212_FastHub
Screenshot_20220511-230039_FastHub

Sent from my SM-G988U using FastHub

@wil-se
Copy link

wil-se commented Dec 22, 2022

same issue for me, mui5 css seems being overrided by chonky css

@wil-se
Copy link

wil-se commented Dec 22, 2022

I've found a workaround for React MUI 5
The problem is explained here
So, considering that MUI generates CSS, I taught maybe I could add a prefix to the generated classes, so that they would not clash with the chonky ones.
So I searched on MUI docs and I've found this.
In my case I just had to

import { unstable_ClassNameGenerator as ClassNameGenerator } from '@mui/material/className';
ClassNameGenerator.configure((componentName) => `REPLACE-${componentName}`);
inside src/index.js
maybe you'll need some refactoring but at least it's working

@wil-se
Copy link

wil-se commented Dec 22, 2022

@TimboKZ a quick fix for this problem woud be adding the same lines to the src/index.js of this project, so that the css generated classes won't clash with others

@Puchaczov
Copy link

Hello guys.

None of the above fixes doesn't really worked for me so I decided to do it hard-way and do the update of the packages to support the MUI v5. After quite some time of digging and changing here and there I finally got something that works.

It's here:

https://github.com/Puchaczov/Chonky/tree/update-dependencies

I also tried to bump up the react version hovewer there was too many typing issues (& probably because of breaking changes) so I decided to not upgrading react & other 'react-like' stuff.

I will monitoring if everything is working fine because I'm going to use it with v5 (and in fact my project uses v5, that's why I had to update dependencies a bit)

to use it on your pages:

cd ./chonky/packages/chonky
npm install
npm pack

It will gives you chonky-2.3.2.tgz. This is something because now you can move generated archive to your project and install it!

just put it in your dependencies: [ "chonky": "file:/some/path/to/tgz/file" ] of your package.json

Here is the post in stackoverflow that describe this process better

https://stackoverflow.com/questions/8088795/installing-a-local-module-using-npm

ciao!

@benkhong
Copy link

benkhong commented Feb 3, 2023

Building on the answers by a few others above and #161

This worked for me. Created a component called ChonkyFullFileBrowser.tsx and imported and used it in place of FullFileBrowser

// ChonkyFullFileBrowser.tsx
import { forwardRef, memo } from 'react';
import {
  StylesProvider,
  createGenerateClassName
} from '@material-ui/core/styles';

import {
  FileBrowser,
  FileList,
  FileContextMenu,
  FileNavbar,
  FileToolbar,
  setChonkyDefaults,
  FileBrowserHandle,
  FileBrowserProps
} from 'chonky';

import { ChonkyIconFA } from 'chonky-icon-fontawesome';

setChonkyDefaults({ iconComponent: ChonkyIconFA });

const muiJSSClassNameGenerator = createGenerateClassName({
  // Seed property is used to add a prefix classes generated by material ui.
  seed: 'chonky'
});

export const ChonkyFullFileBrowser = memo(
  forwardRef<FileBrowserHandle, FileBrowserProps>((props, ref) => {
    const { onScroll } = props;
    return (
      <StylesProvider generateClassName={muiJSSClassNameGenerator}>
        <FileBrowser ref={ref} {...props}>
          <FileNavbar />
          <FileToolbar />
          <FileList onScroll={onScroll} />
          <FileContextMenu />
        </FileBrowser>
      </StylesProvider>
    );
  })
);

@Egzscure
Copy link

Egzscure commented Jan 19, 2024

Still not fixed.

All the "solutions" require using outdated "mui" or using "dubious" hack ways.

@aaraney
Copy link

aaraney commented Jan 22, 2024

@Egzscure, it appears that the maintainer has more or less abandoned the project. You may have a go with this fork: https://github.com/aperturerobotics/react-chonky. Ive not tried it myself, but it appears to be under active maintenance. Best of luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests