inertia-laravel
inertia-laravel copied to clipboard
Check if page components exist
Currently the testing framework allows you to test if a page component actually exists. This behaviour is configured in the /config/inertia.php file:
'testing' => [
'ensure_pages_exist' => true,
'page_paths' => [
resource_path('js/Pages'),
],
'page_extensions' => ['js', 'svelte', 'ts', 'vue'],
],
However, it would be great to do this all the time. Currently if you try to visit a page that has a component that doesn't exist, an exception isn't thrown. All you get is a console error. In production, this is especially problematic, because the user has no idea something went wrong.
Is there any reason why we can't just do this automatically all the time? Yes, there would be an extremely minor performance hit to checking if the file exists. That practically doesn't seem like a real issue.
I'm thinking that we remove the testing property from the config, and just have these options available top level. The ensure_pages_exist property could accept an array of environments to run this check in:
'ensure_pages_exist' => ['local', 'production', 'testing'], // or set to "true" for always
'page_paths' => [
resource_path('js/Pages'),
],
'page_extensions' => ['js', 'svelte', 'ts', 'vue'],
Honestly, I don't see why you'd want to do this as part of every request, as once a deployment is live, all but the initial request (meaning, the 99.99%) will be unnecessary overhead that doesn't add any real value?
Instead, if this is a real concern, I'd probably use a bug-tracking library on the JS-side of things (which, with a large JS app, isn't a bad idea anyway) that automatically reports console errors/bugs to a bug tracker like https://docs.bugsnag.com/platforms/javascript/
I mean, the alternative is catching it on your back-end, and then sending it to the same bug tracker, but then it involves extra logic, and the whole extra filesystem check that just generally feels unnecessary.