-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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! 💯
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? |
@cristianbote Good point, added those 👍 |
Alright, made a few changes and I think now it's ready for another review round. These are the changes:
|
There was a problem hiding this 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!
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
There was a problem hiding this 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.
// | ||
// Option hooks | ||
// | ||
// These are using the public types to avoid conflicts. Downside of that |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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.
* @param {import('../../src/internal').Options} options | ||
* @param {import('../../src/internal').Options["_commit"]} fn | ||
*/ | ||
export function setOptionsCommit(options, fn) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@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? |
e51907d
to
ba13d9e
Compare
FYI: We disabled running our benchmark tests on our CI with #2167. |
Let's merge this all right? |
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';
}); |
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.