nova-scheduled-jobs icon indicating copy to clipboard operation
nova-scheduled-jobs copied to clipboard

[BUG]: JavaScript Error on load

Open kaiserkiwi opened this issue 2 years ago • 13 comments

Description of the bug

image

I just installed this Package into my configured Nova installation and wanted to try it out. Sadly I alway get an JavaScript-Error. The message implies, that the jobs variable is undefined. But my jobs run totally fine. So I really don't have any idea what I could do. The installation process is not really complicated and I made exactly the same with the Nova Queues Package.

The error is on the single page and on the card aswell.

Steps To Reproduce

  1. Follow installation instructions.
  2. Go to your nova route.
  3. Open the Dev-Tools
  4. See the error

Additional Information

Plugin-Version: 6.0.1 Laravel-Version: 9.43.0 Nova-Version: 4.19.4 PHP-Verison: 8.1.12 Packages that could interfere: https://github.com/den1n/nova-queues

kaiserkiwi avatar Dec 07 '22 16:12 kaiserkiwi

@kaiserkiwi I was not able to reproduce this with the same versions you listed. It's possible there is an issue with what the endpoint is returning based on the events you have scheduled, either a bug or use case this package doesn't currently handle. Can you share your Console/Kernel.php file and check if the server is returning a valid response for the endpoint that returns the jobs?

llaski avatar Dec 08 '22 04:12 llaski

Sure. Here ist my Console/Kernel.php nothing wild.

<?php

namespace App\Console;

use App\Actions\Questlog\Fetch\FetchGames;
use App\Actions\Questlog\Fetch\FetchGenres;
use App\Actions\Questlog\Fetch\FetchPlatforms;
use App\Actions\Questlog\Fetch\UpdateGames;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
	/**
	 * The Artisan commands provided by your application.
	 *
	 * @var array
	 */
	protected $commands = [
		FetchGames::class,
		FetchGenres::class,
		FetchPlatforms::class,
		UpdateGames::class
	];

	/**
	 * Define the application's command schedule.
	 *
	 * @param Schedule $schedule
	 *
	 * @return void
	 */
	protected function schedule(Schedule $schedule): void
	{
		 $schedule->command('fetch:platforms')->daily();
		 $schedule->command('fetch:genres')->daily();
		 $schedule->command('update:games')->everyMinute();
	}

	/**
	 * Register the commands for the application.
	 *
	 * @return void
	 */
	protected function commands()
	{
		$this->load(__DIR__ . '/Commands');

		require base_path('routes/console.php');
	}
}

And this is the response from the jobs endpoint:

[
  {
    "command": "php artisan fetch:platforms",
    "description": "",
    "expression": "0 0 * * *",
    "expressionHumanReadable": "At 00:00 on every day.",
    "timezone": "UTC",
    "nextDue": "2022-12-09 00:00:00 +00:00",
    "nextDueHumanReadable": "in 14 Stunden",
    "withoutOverlapping": false,
    "onOneServer": false,
    "runInBackground": false,
    "evenInMaintenanceMode": false
  },
  {
    "command": "php artisan fetch:genres",
    "description": "",
    "expression": "0 0 * * *",
    "expressionHumanReadable": "At 00:00 on every day.",
    "timezone": "UTC",
    "nextDue": "2022-12-09 00:00:00 +00:00",
    "nextDueHumanReadable": "in 14 Stunden",
    "withoutOverlapping": false,
    "onOneServer": false,
    "runInBackground": false,
    "evenInMaintenanceMode": false
  },
  {
    "command": "php artisan update:games",
    "description": "",
    "expression": "* * * * *",
    "expressionHumanReadable": "Every minute on every day.",
    "timezone": "UTC",
    "nextDue": "2022-12-08 09:24:00 +00:00",
    "nextDueHumanReadable": "in 15 Sekunden",
    "withoutOverlapping": false,
    "onOneServer": false,
    "runInBackground": false,
    "evenInMaintenanceMode": false
  }
]

kaiserkiwi avatar Dec 08 '22 09:12 kaiserkiwi

@kaiserkiwi So that response is interesting - it's actually missing a level of nesting. It should be:

{
   "data":[
      {
         "command":"php artisan fetch:platforms",
         "description":"",
         "expression":"0 0 * * *",
         "expressionHumanReadable":"At 00:00 on every day.",
         "timezone":"UTC",
         "nextDue":"2022-12-09 00:00:00 +00:00",
         "nextDueHumanReadable":"in 14 Stunden",
         "withoutOverlapping":false,
         "onOneServer":false,
         "runInBackground":false,
         "evenInMaintenanceMode":false
      },
      {
         "command":"php artisan fetch:genres",
         "description":"",
         "expression":"0 0 * * *",
         "expressionHumanReadable":"At 00:00 on every day.",
         "timezone":"UTC",
         "nextDue":"2022-12-09 00:00:00 +00:00",
         "nextDueHumanReadable":"in 14 Stunden",
         "withoutOverlapping":false,
         "onOneServer":false,
         "runInBackground":false,
         "evenInMaintenanceMode":false
      },
      {
         "command":"php artisan update:games",
         "description":"",
         "expression":"* * * * *",
         "expressionHumanReadable":"Every minute on every day.",
         "timezone":"UTC",
         "nextDue":"2022-12-08 09:24:00 +00:00",
         "nextDueHumanReadable":"in 15 Sekunden",
         "withoutOverlapping":false,
         "onOneServer":false,
         "runInBackground":false,
         "evenInMaintenanceMode":false
      }
   ]
}

That is prob the culprit here - do you have any custom middleware or do any customization to the collection resource wrapper?

llaski avatar Dec 10 '22 02:12 llaski

That could be the problem. I have the line JsonResource::withoutWrapping(); in my AppServiceProvider for some specific reasons.

Would it be possible to alter your package to catch this edge case or should I try to rework my code to get it working?

kaiserkiwi avatar Dec 10 '22 08:12 kaiserkiwi

Hi, I'm finally back on my Notebook. If I comment out JsonResource::withoutWrapping(); then it instantly works. As that's something that is mentioned in the docs (https://laravel.com/docs/9.x/eloquent-resources#data-wrapping) I would guess my project is not the only one that uses it.

So it would be awesome, if you could catch this edge case.

kaiserkiwi avatar Dec 11 '22 14:12 kaiserkiwi

Any news an this? 🙂

kaiserkiwi avatar Jan 01 '23 16:01 kaiserkiwi

@kaiserkiwi I don't have time to currently address this but feel free to open a PR. Will see if I can review in the next month or two.

llaski avatar Mar 09 '23 03:03 llaski

Do we have any news on this? @llaski I can totally open a PR with a fix, but my lack of knowledge/experience makes a bit difficult for me to debug the code. Can you help me with a general idea of what might be causing the bug? Anything would help. I can continue after that.

Also @kaiserkiwi would be great to know if you found any workaround this

devnicolas1 avatar Aug 21 '23 13:08 devnicolas1

I sadly hadn't the time to research this further. As far as I remember the error was in the reaponse part of the AJAX request. The wrapping data is expected and it comes to an error.

As I will switch to Filament (because of the stagnation of Nova) I probably won't research this anymore even if I have the time. Sorry.

kaiserkiwi avatar Aug 22 '23 05:08 kaiserkiwi

Thats totally okay! Thanks anyway :)

devnicolas1 avatar Aug 22 '23 12:08 devnicolas1

@devnicolas1 @kaiserkiwi I also have not had much time to look into this. I did spend a few minutes on seeing if there was an easy way to fix this but requires more investigation/though on how to resolve this.

@kaiserkiwi @devnicolas1 I'm not familiar with filament but have seen v3 was released and it seems to be very popular. Do you know if filament has a package that handles what this package does already? If not may look at learning filament and porting this over.

llaski avatar Aug 25 '23 19:08 llaski

@llaski I have no knowledge/experience with Filament, but it does look pretty cool. I'll be putting my hands into it soon, and I'll let you know if I find any alternative to this package :)

devnicolas1 avatar Aug 30 '23 20:08 devnicolas1

@llaski Looks like this is a similar package for Filament: https://filamentphp.com/plugins/husam-database-schedule

kaiserkiwi avatar Sep 13 '23 13:09 kaiserkiwi