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

Add shared-internals package #2160

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Add shared-internals package #2160

wants to merge 12 commits into from

Conversation

marvinhagemeister
Copy link
Member

As discussed in our monthly meeting, here is the package with the internal getter and setter methods intended for debugging/testing enhancements. For this I combined all the mangled names I could find in enzyme-adapter-preact-pure and our (yet to be released) preact-devtools.

@coveralls
Copy link

coveralls commented Nov 29, 2019

Coverage Status

Coverage decreased (-1.3%) to 96.331% when pulling d2dcbc2 on shared-internals into 5d1dc19 on master.

Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

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

This is in line with how I was thinking of it, nice work Marvin! 💯

@cristianbote
Copy link
Member

I've used this in the past https://github.com/duxiaofeng-github/preact-responder-event-plugin/blob/master/src/index.ts#L8 maybe we could add it? What do you think?

@marvinhagemeister
Copy link
Member Author

@cristianbote Good point, added those 👍

@marvinhagemeister
Copy link
Member Author

marvinhagemeister commented Nov 29, 2019

Alright, made a few changes and I think now it's ready for another review round. These are the changes:

  • Add tests
  • Remove getter for _lastDomChild because we only use it inside diffChildren and reset it immediately to null. So the getter would always return null in every scenario.

Copy link
Member

@cristianbote cristianbote left a comment

Choose a reason for hiding this comment

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

🎉 awesome job, Marvin! This will help a lot!

robertknight added a commit to preactjs/enzyme-adapter-preact-pure that referenced this pull request Dec 2, 2019
Replace references to private vnode properties with functions from the
shared-internals package [1]. This reduces the risk that a minor or
patch Preact release will break the adapter.

[1] preactjs/preact#2160
Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

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

I created preactjs/enzyme-adapter-preact-pure#86 to test this locally. It looks great except that the test adapter is still missing a function to get the root vnode rendered into a given DOM node. This is the _children property set on DOM container nodes.

shared-internals/src/index.js Outdated Show resolved Hide resolved
shared-internals/src/index.js Outdated Show resolved Hide resolved
//
// Option hooks
//
// These are using the public types to avoid conflicts. Downside of that
Copy link
Member

Choose a reason for hiding this comment

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

By "public types" do you mean "public types for the arguments". Are they different from "private types"?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's referring to our public Options type. It doesn't have the internal _commit/_root/_diff properties in the interface. Extending the existing interface would be incorrect as our private property names are mangled.

shared-internals/README.md Show resolved Hide resolved
* @param {import('../../src/internal').Options} options
* @param {import('../../src/internal').Options["_commit"]} fn
*/
export function setOptionsCommit(options, fn) {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm is little nervous exposing this option before we do 2 phase render. By exposing the option we also expose it's contract (i.e. arguments) and I suspect the commit option will change after 2 phase (personally think it might be interesting to rewrite commit option to enable different renders).

Which libraries is this need for? Devtools? I also really want the devtools lol

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a very good point! For now the devtools "bridge" will likely live in preact/debug so there is no immediate need for the devtools expose this. We do have one known outside consumer though: https://github.com/duxiaofeng-github/preact-responder-event-plugin/blob/master/src/index.ts#L8 . Same is true for the Composition API in #1923 .

I'm wondering if a 2-phase renderer would be released as semver major or minor. It shouldn't be a visible breaking change for users from an API point of view though.

I'm admittedly a bit torn. On the one hand I'm ok with doing breaking changes here for our shared internals, but on the other hand we likely will have users depend on it at some point.

@marvinhagemeister
Copy link
Member Author

@andrewiggins The performance tests are causing the build failures. I'm wondering if the issue is the way they are run on Travis. Our suite assumes that they'll be executed under the same conditions but maybe we get a different machine/vm on each run with different specs?

@marvinhagemeister
Copy link
Member Author

FYI: We disabled running our benchmark tests on our CI with #2167.

@JoviDeCroock
Copy link
Member

Let's merge this all right?

@developit
Copy link
Member

Apologies for being super late to review this one. A thought on the hook abstraction: what if we abstracted the calling of old hooks? Something like an Express middleware:

function empty() {}

export function installCommitHook(options, hookFn) {
  const old = options._commit || empty;
  // we only have hooks with up to 2 arguments
  options._commit = (a, b) => hookFn(old, a, b);
}

This would allow hooks to decide when to call their originals, like before and after middleware:

installCommitHook(options, (next, vnode) => {
  // run any previous commit hook:
  next(vnode);
  vnode.foo = 'bar';
});

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.

7 participants