-
Notifications
You must be signed in to change notification settings - Fork 4
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
Task Handler arrow function property names are sometimes an empty string #453
Comments
property.name
being an empty string
Ok so with an async arrow function, one must be aware that the arrow function Problem is... what is the "parent closure" of an arrow function? Well usually it is whatever is defining it. But if you're defining it in a class... then Let's try this: class X {
static a () {
console.log('1', this.constructor.name);
console.log('2', this.name);
}
b = () => {
console.log('3', this.constructor.name);
// @ts-ignore
console.log('4', this.name);
console.log('5', this.c);
console.log('6', this.b.name);
};
c = 3;
}
console.log(X.a());
const x = new X();
console.log(x.b()); Running it gives us:
Therefore in static functions, the So for |
My tests show that this shouldn't happen. With swc or otherwise. If it does still show up... we may just change the handler name and hardcode it instead. |
I'm just thinking there could be an ordering issue with:
That seems like something that may just need to be inlined wherever it is used. |
@tegefaulkes I can't find anywhere in the code where we are doing this, as in setting it as a property. Is this issue even relevant anymore? |
Ok I see it like:
I think this can be remove in favour of inlining this sort of stuff. The whole idea is that his is supposed to be set when the instance is created. If you want to do this sort of stuff, prefer setting it in the constructor instead, or even just dynamically created in the functions themselves. In fact the usage of |
In
So I think hardcoding it, with only |
This is a quick fix @tegefaulkes. |
We're just going to hard-code the handler IDs now just to keep it simple. This should be resolved once we make this change to all handler IDs. |
Seems like constructor name works fine. But just hardcode the name of the handler. |
Should have this in the documentation too. |
@tegefaulkes if we have decided to just hardcode the handler IDs, then you can close this (technically a workaround, not a fix but whatever). |
But make sure it's applied all over the place. Should not have any inconsistency. Commit message should refer to this issue #453 for background context. |
From what I understand, this is a similar problem that React anonymous components have: https://julesblom.com/writing/component-displayname The solution for dealing with it there is just to hardcode the fn component displayName, no other way. |
I've found one last place that the public readonly discoverVertexHandlerId =
`${this.constructor.name}.${this.discoverVertexHandler.name}.discoverVertexHandlerId` as TaskHandlerId; Just to clarify, is this meant to be just Because the naming convention for all of these TaskHandlerIds seem to be |
It used to be It should just be the |
…no longer use the `name` property of the handler function due to #453
THis has been fixed by 80ac79d |
Specification
In the
NodeManager
we make use of 3 handlers with the task system. Their handler IDs are public read only properties that arepublic readonly handlerId = '${this.constructor.name}.${this.handler.name}' as HandlerId
.this.handler
is an async arrow function used as a handler for a task. ThehandlerId
should be'NodeManager.handler'
.The problem is, in some cases the
this.handler.name
has the value of''
as an empty string. The weird thing is, in a simple test where we just construct theNodeManager
and check it we get the expected values. When we do more complex tests within the nodes domain we see the empty strings resulting in errors.My first guess is it's the same decorator problem we had to fix for the
this.constructor.name
when we switched to SWC. I'm guessing when we start theNodeManager
it overwrites the property names? More exploration on this is needed.Additional context
Tasks
The text was updated successfully, but these errors were encountered: