Golfing: Par 4#2665
Conversation
|
Size Change: -618 B (1%) Total Size: 40.3 kB
ℹ️ View Unchanged
|
|
This is fantastic! 🙌 |
|
boom! 💥 🔥 😄 |
| return createElement(c, props); | ||
| } | ||
| Memoed.prototype.isReactComponent = true; | ||
| Memoed.displayName = 'Memo(' + (c.displayName || c.name) + ')'; |
There was a problem hiding this comment.
Things like this make me wonder whether we should ship a "development" and a "production" version. I remember the discussions about making things more complex bundling wise but couldn't we omit this line in a "production" or "minimal" variant of our build? That would save us some bytes here and there.
Or are we somehow able to move this line to debug? I though about monkey patching the exported function but that only works in CJS and not ESM AFAIK.
There was a problem hiding this comment.
I was pondering this. There's no usable way to ship debug variants today, and we get a lot of value out of avoiding pushing that stuff onto users. But I think there may be a compromise solution possible: preact/debug can actually set this on its own:
// memo.js
Memoed.displayName = 'Memo(';// forwardRef.js
Forwarded.displayName = 'forwardRef(';import { options } from 'preact';
options.vnode = (vnode) => {
if (typeof vnode.type === 'function') {
// turn "Memo(" into "Memo(ChildName)" the first time we see a constructor
if (/\(/.test(vnode.type.displayName)) {
const child = vnode.type.call({}).type;
vnode.type.displayName += (child.displayName || child.name) + ')';
}
}
};There was a problem hiding this comment.
It would require us striping forwardRef and memo out of compat if I'm reading that correctly, right?
There was a problem hiding this comment.
@marvinhagemeister I'd hoped the above would avoid that - instead of relying on vnode.type === Memo, it uses the (-suffixed name as an indication that displayName should be regenerated to include the child component's displayName.
This is probably a non-zero perf hit in preact/debug though, with or without compat enabled. Might not be worth it.
| * TODO: this could use the "fake root node" trick from the partial hydration demo | ||
| */ | ||
| function Portal(props) { | ||
| let _this = this; |
There was a problem hiding this comment.
What is the reason for dropping this? Would save us 2 bytes keeping the let _this = this and using _this afterwards
There was a problem hiding this comment.
yeah I was 50/50 on this. I think some more refactoring can get the total down, but the _this alias was masking some of the other possible changes. I was mostly just trying to switch out arrow functions that had the possibility to cause accidental closures for this access.
| if (isSvg) { | ||
| if (name === 'className') { | ||
| name = 'class'; | ||
| } | ||
| } else if (name === 'class') { | ||
| name = 'className'; | ||
| } | ||
| if (isSvg && name == 'className') name = 'class'; |
There was a problem hiding this comment.
I'm curious if anyone is opposed to this change. It means we would be using setAttribute("class") for a class prop and .className= for a className prop. They're the same thing, but it's possible there's a performance difference.
* Use _this = this in portals * Remove _this = this in suspense-list
|
Might be okay to merge this now. Thoughts? |
No description provided.