Skip to content

Golfing: Par 4#2665

Merged
JoviDeCroock merged 13 commits intomasterfrom
golfing-par-4
Aug 17, 2020
Merged

Golfing: Par 4#2665
JoviDeCroock merged 13 commits intomasterfrom
golfing-par-4

Conversation

@developit
Copy link
Copy Markdown
Member

No description provided.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jul 30, 2020

Size Change: -618 B (1%)

Total Size: 40.3 kB

Filename Size Change
compat/dist/compat.js 3.26 kB -115 B (3%)
compat/dist/compat.module.js 3.29 kB -107 B (3%)
compat/dist/compat.umd.js 3.33 kB -108 B (3%)
dist/preact.js 3.9 kB -75 B (1%)
dist/preact.min.js 3.92 kB -74 B (1%)
dist/preact.module.js 3.92 kB -72 B (1%)
dist/preact.umd.js 3.96 kB -67 B (1%)
ℹ️ View Unchanged
Filename Size Change
debug/dist/debug.js 3.06 kB 0 B
debug/dist/debug.module.js 3.06 kB 0 B
debug/dist/debug.umd.js 3.15 kB 0 B
devtools/dist/devtools.js 185 B 0 B
devtools/dist/devtools.module.js 195 B 0 B
devtools/dist/devtools.umd.js 260 B 0 B
hooks/dist/hooks.js 1.09 kB 0 B
hooks/dist/hooks.module.js 1.11 kB 0 B
hooks/dist/hooks.umd.js 1.17 kB 0 B
test-utils/dist/testUtils.js 437 B 0 B
test-utils/dist/testUtils.module.js 439 B 0 B
test-utils/dist/testUtils.umd.js 515 B 0 B

compressed-size-action

Comment thread compat/src/Children.js
@marvinhagemeister
Copy link
Copy Markdown
Member

This is fantastic! 🙌

@cristianbote
Copy link
Copy Markdown
Member

boom! 💥 🔥 😄

Comment thread compat/src/memo.js
return createElement(c, props);
}
Memoed.prototype.isReactComponent = true;
Memoed.displayName = 'Memo(' + (c.displayName || c.name) + ')';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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) + ')';
    }
  }
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would require us striping forwardRef and memo out of compat if I'm reading that correctly, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@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.

Comment thread compat/src/portals.js
* TODO: this could use the "fake root node" trick from the partial hydration demo
*/
function Portal(props) {
let _this = this;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the reason for dropping this? Would save us 2 bytes keeping the let _this = this and using _this afterwards

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@coveralls
Copy link
Copy Markdown

coveralls commented Jul 30, 2020

Coverage Status

Coverage decreased (-0.0004%) to 99.803% when pulling 16ab933 on golfing-par-4 into cfbe0c3 on master.

Comment thread src/diff/props.js
Comment on lines -62 to +61
if (isSvg) {
if (name === 'className') {
name = 'class';
}
} else if (name === 'class') {
name = 'className';
}
if (isSvg && name == 'className') name = 'class';
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@developit developit changed the title Golfing par 4 Golfing: Par 4 Jul 30, 2020
sventschui and others added 3 commits August 9, 2020 18:08
@developit
Copy link
Copy Markdown
Member Author

Might be okay to merge this now. Thoughts?

@developit developit marked this pull request as ready for review August 13, 2020 13:10
@JoviDeCroock JoviDeCroock merged commit df748d1 into master Aug 17, 2020
@JoviDeCroock JoviDeCroock deleted the golfing-par-4 branch August 17, 2020 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants