Skip to content
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

[Bug]: Inertia view not found #109

Closed
wfern opened this issue Dec 21, 2024 · 8 comments
Closed

[Bug]: Inertia view not found #109

wfern opened this issue Dec 21, 2024 · 8 comments
Assignees
Labels

Comments

@wfern
Copy link

wfern commented Dec 21, 2024

Extension Version

0.1.14

PHP Binary

Herd

Operating System

macOS

What happened?

I'm using the version 0.1.14 from this extension and still not finding my inertia views.

I'm using vite with react.js and typescript in a "custom" directory, so my views is in this path:

resouces/js/pages/payment.tsx

On controllers and routes using inertia helper:

Route::inertia('pagamento', 'payment');
// or as controller return
return inertia('payment');

shows

Inertia view [payment] not found.  Laravel Extension(inertia)

My views lives in resources/js/pages.

My createInertiaApp in resources/js/app.tsx:

createInertiaApp({
  resolve: (name) => {
    const pages = import.meta.glob('./pages/**/*.jsx', { eager: true });
    return pages[`./pages/${name}.jsx`];
  },
  setup({ el, App, props }) {
    createRoot(el).render(<App {...props} />);
  },
  progress: {
    color: 'var(--primary)',
  },
  title: (title) => {
    const appName = import.meta.env.VITE_APP_NAME;

    if (!title) {
      return appName;
    }

    return `${title} - ${appName}`;
  },
});

.
.
.

Current solution

Based on the PR #20 the solution on 0.1.13 was getting the path from the inertia config file but I don't have one in my project and never had the need to publish it. I think Inertia don't publish it on install too?

It works after publish the inertia config file through php artisan vendor:publish and select Inertia\ServiceProvider.

.
.
.

Custom inertia resolve method issue

Maybe having a option in the extension for inertia view path is not a bad thing because it's easier to discover that than to discover you need to publish the inertia config for the extension work and it's a good thing too to custom resolve implementations.

Like this one I have in one project to auto-discover {page}/index.tsx files. Instead of type inertia('payment/index) I only type inertia('payment') (Both works btw). My inertia resolve method:

resolve: (name) => {
  const pages = import.meta.glob(['./pages/**/*.tsx'], {
    eager: true,
  });

  const page =
    pages[`./pages/${name}/index.tsx`] ||
    pages[`./pages/${name}.tsx`];

  return page;
}

Mimimal Code Sample

No response

@kimhout-sam
Copy link

you need manual publish

@wfern
Copy link
Author

wfern commented Dec 21, 2024

Yeah, i find out in the #20 and write about the solution in the issue.

But I think we could have another way without depending of the testing config or at least having instructions in the docs/readme for now.

@lcdss
Copy link

lcdss commented Dec 22, 2024

You can set the config directly in the boot method of your AppServiceProvider:

<?php

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        Vite::prefetch(concurrency: 3);

        // Override Inertia's default page paths so Laravel VS Code extension can find them
        config(['inertia.testing.page_paths' => [resource_path('js/pages')]]);
    }
}

So no need to publish a config you don't need in your project now, but yeah, the current solution looks like a work around and not an actual solution.

@frankmichel
Copy link

frankmichel commented Dec 22, 2024

On a Mac, the "Inertia view is not found" message returns after the file has been changed from uppercase to lowercase.

For example, having this:

return Inertia::render('Welcome', [...])

with a Welcome.vue file

and then changing the file in the filesystem to welcome.vue and subsequently changing the code to:

return Inertia::render('welcome', [...])

it will show the "Inertia view is not found" message again and 'welcome' will be underlined.

It will work after restarting VSCode, though.

@wfern
Copy link
Author

wfern commented Dec 22, 2024

@frankmichel maybe i'm wrong but i think this is related to a very old issue in vscode microsoft/vscode#94307 (theres other issues in the repo too related to case sensitivity systems/volumes not only on macos).

Like, every time I rename a file using vscode file tree or in finder it don't show the new file and sometime show the original as deleted and only work after restarting vscode).

@joetannenbaum
Copy link
Collaborator

This should be resolved as of v0.1.17 as long as inertia.testing.page_paths is configured correctly, please re-open if the issue persists.

@kusaasira
Copy link

@joetannenbaum Quick question - where do I configure inertia.testing.page.paths in v1.0.0? Do I still need to manually add it to AppServiceProvider as @lcdss suggested? I'm getting warnings in my Laravel 12 app, even though the file exists in the default installation. Would appreciate your guidance!

Image

@dustin-dean
Copy link

I am also having the same issue with Laravel 12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants