-
-
Notifications
You must be signed in to change notification settings - Fork 148
Breaking in combination with Material UI #234
Comments
Strange, I've never heard of that method. You could try patching it in: import { options } from 'preact';
options.event = e => {
e.persist = () => {};
}; |
Ah, yes, i did something like similar to that and thought it should work because by looking at the React source it seems to have something to do with persisting the event from their event pool. So i thought it shouldn't affect Preact and it seems like it doesn't. However the button is still not clickable. I think this has to do with
I wasn't able to find something similar to Because the current application(with your fix for the Thanks for your help so far @developit |
This is really good, I've been hoping to get proper support for Material UI in for some time now. I think we can definitely add the |
Yeah, this combined with #236 will hopefully make MUI run smooth(er) The application i tried this out on was pretty complex and other than the click-events(touch-tap) everything seemed fine. As for the tap-plugin, yeah it's to make No, i don't have any public repo unfortunately but i can set up a small repo which will have the same symptoms. I'm kind of interested in what |
Alright, so after some snooping around it seems like React listens for events on the document which are then passed to the event system which in turn passes it to plugins which in their turn either return null or a SyntheticEvent. Then i'm guessing React just looks at what type of event that is and calls the callback. So as i understand it: If a We could try one of these approaches:
|
Definitely have to go with #1 - synthetic events is one of the things that makes React larger than Preact. I think your first option is pretty good, and the radius detection should be pretty quick to implement. I actually believe I have a demo somewhere of this technique as a preact plugin... |
The problem with option 1 however is that components that listen to both onTouchTap and onClick events(see this example, used by all MUI buttons)
React is able to differentiate between these because the underlying events are not I really think we have to implement |
Likely will have to use a proxy handler that does the type negotiation when the event is triggered. I agree though, my thinking was that a VNode Hook would work for massaging the props to add those multiple listeners to fire the meta-event. |
Ah yeah, i was thinking about something similar with the multiple listeners but i'm not too familiar with the code yet. If you solve it i'd like to have a look 👍 |
Will do, I'll loop you in on the PR! |
Any progress on this front? Looking to use preact with material-ui as well. |
I have, with a hack, successfully gotten Material UI to work without(afaik) any issues. However i'm hoping developit has a better solution since mine was just a hack to make it work. But to me it seems that we are very close to being compatible with MUI |
I think you had the wrong issue. This one is about touchtap. Anyway thats what i tried to make refs work but i think i still had problems after doing so because then some refs were not fired. I will come back with results and tag you in the other issue. Maybe, since there were s few other issues making MUI break, i should just change the title to something about touchtap! :-) |
@linde12 Do you had any news? I can get AppBar running by monkeypatching event.persist but I can't get through onTouchTap |
…not needed for DOM events). See #234
@cia48621793 I just pushed the persist fix, but I'm wondering if adding |
Didnt know there is an active discussion going on in this. These are still an issue. https://cl.ly/2u2M1x183E2p |
@harshmaur the issue is that |
@harshmaur @cia48621793 I think it's as @developit says that we need a replacement I don't think it would be difficult for a user to replace that plugin with a preact counterpart, let's say I'm not entirely sure how the API for the event system in preact in terms of hooks looks today but maybe we will need some changes to allow this sort of behavior? What needs to happen is that |
@linde12 I am not sure how replacing would work with material-ui as it tightly integrates with onTouchTap events. The source code also contains their own modifiers like onActionTouchTap events and so on. If there is a plugin that gives |
@harshmaur Material-UI has a peerDependency towards And tl;dr MUI isn't dependent on |
@linde12 Totally agreed with your point. |
Wouldn't the |
@developit the latter. material-ui works without react-tap-event-plugin but it wants it to be installed separately. If there is a custom lib that provides for BTW, material-ui@next branch is supposed to work without onTouchTap, however the release is not going to happen any soon. |
I wonder - would it suffice to have a package that could be aliased in for import { options } from 'preact';
const opts = {
// # of pixels after which to discount as drag op
threshold: 5
};
let oldHook = options.vnode;
options.vnode = vnode => {
let attrs = vnode.attributes;
if (attrs) {
let map = {};
for (let i in attrs) map[i.toLowerCase()] = i;
if (map.ontouchtap) proxy(attrs, map);
}
if (oldHook) oldHook(vnode);
};
function proxy(attrs, map) {
let start = attrs[map.ontouchstart],
end = attrs[map.ontouchend],
tap = attrs[map.ontouchtap],
coords = e => ({ x: e.touches[0].pageX, y: e.touches[0].pageY });
down;
delete attrs[map.ontouchtap];
attrs[map.ontouchstart || 'onTouchStart'] = e => {
down = coords(e);
return start(e);
};
attrs[map.ontouchend || 'onTouchEnd'] = e => {
let up = coords(e),
ret = end && end(e),
dist = Math.sqrt( Math.pow(up.x-down.x) +Math.pow(up.y-down.y) );
if (down && ret!==false && dist<opts.threshold) tap(e); // or createEvent('touchtap')
return ret;
};
}
// in case someone calls inject():
export default (newOpts) => {
Object.assign(opts, newOpts);
}; |
This looks promising! I don't even think you would have to use an alias if unless you don't want to. It's a separate peerDependency so all that would happen is that npm would complain that the dependency isn't satisfied(which it wouldn't be with an alias anyway?) |
npm complaining wouldnt be a problem if aliasing works. |
Plus this can be a separate package that might actually be useful beyond getting MUI working - anyone who wants basic FastClick style tap events could use it. Not as elegant as a compositional component, but simple once installed. |
@developit React-Lite had their solution of touchtap with @fastclick but it won't work with Preact. |
Okay I tried removing the react-tap-event-plugin and replaced with the sample code. the app kind of loaded, but it doesnt seem to work properly, the elements which do implement |
Yep, sorry - meant remove tap event plugin. Any chance the app you're working on is Open Source so I can check it out and test? :) It also should have worked when aliased. It seemed like you actually imported it into webpack, really you just want to reference the filename: resolve: {
alias: {
'react-tap-event-plugin': 'path/to/that/file.js'
}
} |
The project is not open source unfortunately. Also, removing the plugin and using it like this seemed to build the project properly // Some custom requirement from touch
import reactTapAlternative from './hoc/reactTapAlternative';
reactTapAlternative(); instead of // Some custom requirement from touch
import injectTapEventPlugin from 'react-tap-event-plugin';
injectTapEventPlugin(); I also tried to resolve however I started getting this.
|
That error is very strange - it's trying to load a module called With the alternative import style it builds, but you dont have tap events, right? |
okay, so I did a silly mistake of aliasing a wrong path. However the end result seems to the same. The app works, but |
Alright, I fixed the code sample and published it as preact-tap-event-plugin 👍 Here's a JSFiddle demo of |
I'm wondering how far we've gotten toward a fully working Material UI now that these two issues are fixed. Anyone know? |
Are the transitions working properly? In my case I do not see transitions properly. Here is the preact version https://cl.ly/3A360X2A0S3e Here is the react version https://cl.ly/2k473X211Y2b |
Hmm - strange. They're not using any translation library, the draw literally just sets properties on import { options } from 'preact';
options.debounceRendering = f => f(); |
I shamelessly tried to compile the material-ui/docs with preact-compat, shallow-compare and preact-tap-event-plugin with only one single error. To emphasize, it's one single error. Not sure about actual rendering tho.
@developit Please fix. |
Hey @cia48621793, there is a bug in the The error you are getting is caused due to react-addons-perf so it needs to be aliased with something that is compatible with preact. I am not too sure if there is something already, but you can remove the lib and try to compile. |
@harshmaur Thanks for the tip. So far so good. The front page is perfectly rendered. Unfortunately, the preact-tap-event-plugin didn't seems to work and I can't pop the menu up. Looking for a fix, any assistance for me? |
@cia48621793 True. @developit is working on the fix, we will soon have it. |
@harshmaur Thanks man. It's prestigious to see Material-UI be ran flawlessly so that more and more developers are siphoned to use Preact. |
@cia48621793 - is it possible that ReactPerf import error only shows up when running the development server (webpack-dev-server)? I can create an alias, will have to look into what it should do. |
@developit No, it was hardcoded in src/app/app.js. Comment out that ReactPerf |
@cia48621793 can you put require back and try to See if you get the same error or not. |
@harshmaur Instruction unclear, Not sure if that's a yay or nay.
Modified:
Then
|
I just released a noop'd version of |
@developit However, I couldn't bring up the menu of Material-UI's documentation website.
package.json
IIRC all touchTap related events are not triggered. Please fix. |
Strange. I can have material-ui running fine with independent module, I'm sure it's a webpage problem. At least now we can prove material-ui be compromised with Preact and it will attract more people, if not only me. |
@cia48621793 What do you mean by independent module? |
@harshmaur npm install. I have had it in my another project and MUI works with Preact. Not sure is that because the npm version of MUI is preprocessed with Babel. |
@harshmaur @developit Here's my repo proving that Preact is 'working' with Material-UI Docs: cia48621793/preact-material-ui-docs Try `npm install && npm run start' for a good start. You will soon find errors clicking the item list on the drawer of AppBar. Look for the console error. Please sort them out. |
Will check this out. Thanks for setting things up, makes it a lot easier for me to debug! (there are so many of these large react-based frameworks that I don't personally use, it's hard to keep track) |
Ah! I've unsubscribed from here by mistake. I just saw that you made the |
We also have a large application which uses material-ui and would be glad to beta test any possible fixes. Please buzz me on any updates you want us to try. Thanks! |
Would love to update existing codebase to Preact but we designed it on the MUI components. Please buzz me if there are any fixes. |
Hello!
I am trying to migrate a project from that uses React to Preact.
The project uses the Material UI library by CallEmAll and it doesn't seem to play nice with Preact: Some of their components(like EnhancedButton), call
event.persist()
on aSyntheticEvent
. Instead in Preact this event is aFocusEvent
and does not have the.persist()
method on it. The result is that Material UI buttons(and probably other components) don't work.Does anyone know how this could be fixed? Since out whole application is built using Material-UI it is crucial for it to work, otherwise we're unable to migrate.
The
SyntheticEvent
docs doesn't say much about.persist()
(see: https://facebook.github.io/react/docs/events.html) so it's difficult to understand why it's needed and how it could be fixed.Otherwise, so far, everything else in the migration seems to be working. The components i can see without pressing buttons seem to be properly rendered and work the same way as they would with React.
The text was updated successfully, but these errors were encountered: