laravel / nova-issues

554 stars 35 forks source link

Unhandled Exception in Promise error when using dependsOn callback which sets the field value #6337

Closed lukejwatts closed 5 months ago

lukejwatts commented 5 months ago

Description:

When I use a Text field with a dependsOn I am seeing a delay in the computation based on the fields. In the browser console I'm seeing a lot of Uncaught (in promise) t {message: undefined} errors. When I breakpoint and step through the issue looks to happen for each key down/up (change) event. Looks like it's something to to with the AbortController, but I'm not certain about that.

The field which is being computed does eventually get updated to the correct value, but the time this takes is somewhat random. Could happen immediately after the first field is blurred/unfocused or it could be 5 seconds later.

Detailed steps to reproduce the issue on a fresh Nova installation:

Here is a trimmed down version of my fields method. I'm simply attempting to sum 3 fields to 1 field with a formula for Pounds, Shillings and Pence (LSD):

public function fields(NovaRequest $request)
{
    return [
        ID::make()->sortable(),
        new Panel('Overview', [
            Text::make('Total First Price Pounds', 'total_first_price_pounds')->nullable()->hideFromIndex(),
            Text::make('Total Half Price Pounds', 'total_half_price_pounds')->nullable()->hideFromIndex(),
            Text::make('Total Aftermoney Price Pounds', 'total_aftermoney_pounds')->nullable()->hideFromIndex(),
            Text::make('Total Pounds', 'total_pounds')->nullable()->dependsOn([
                'total_first_price_pounds',
                'total_half_price_pounds',
                'total_aftermoney_pounds',
            ], function (Text $field, NovaRequest $request) {
                $field->value = LSDCalculator::fromReceiptRequest($request)->sum(Unit::POUNDS)->get();
            })
        ])
    ];
}

Unit is an enum with POUNDS, SHILLINGS, PENCE. There are also the same fields for Shillings and Pence which are identical aside from the dependsOn array and the Unit.

As I mentioned, it does work...it's just there are some unhandled exceptions which are causing a delayed, somewhat buggy experience.

I'm not sure if this is the latest version of Nova (I'm on a contract working with an existing application) so this might be something fixed in a newer version.

Thanks for you're help. Nova is awesome BTW!

crynobone commented 5 months ago

Unable to reproduce the issue, please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

lukejwatts commented 5 months ago

Thanks for looking into this.

I think I'll close this as I can't share the repo where I'm experiencing this...and the other dev didn't experience this on their environment when they merged the code in (they are using Mac, and we're not using Docker or Sail at the moment).

So it must be something on my environment. Possibly a Windows specific node issue when the resources are building, as I did get cross_env and webpack errors when I try to run the build scripts manually.

Thanks again. If I do find a reason for it I'll leave a comment here.