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

JS Error On Non-Inertia Pages #134

Open
jakemumu opened this issue Oct 11, 2024 · 3 comments
Open

JS Error On Non-Inertia Pages #134

jakemumu opened this issue Oct 11, 2024 · 3 comments

Comments

@jakemumu
Copy link

jakemumu commented Oct 11, 2024

Hi! Just getting setup with inertia and it's awesome -- I do notice this error though. I'm only planning to use inertia on some pages of my rails app -- but I initialize it on my entrypoint/application.js

When I hit a route which doesn't not render via inertia I get this crash from the initialization of inertia:

Screenshot 2024-10-11 at 10 08 10 AM Screenshot 2024-10-11 at 10 06 42 AM

Is there a way to avoid this? -- I don't see a way at the moment

@PedroAugustoRamalhoDuarte
Copy link
Contributor

@jakemumu to fix that you have to create two layouts and two JavaScript entrypoints; One for Inertia and one for your normal rails views

@jakemumu
Copy link
Author

@jakemumu to fix that you have to create two layouts and two JavaScript entrypoints; One for Inertia and one for your normal rails views

nice!!!

Is there any way for me to help with the project documentation? maybe there is a gotcha or FAQ? -- I would never have guessed that honestly -- wouldn't it be possible to make the library handle that?

@jakemumu
Copy link
Author

For anyone that comes across this here is a solution which makes it possible to retain the same layout & entry point you're already using:

// detect if the data is on the page which indicates it's an inertia render
if (document.querySelector('[data-page]')) {
  createInertiaApp({
    resolve: name => import(`../frontend/${name}.svelte`),
    setup({ el, App, props }) {
      new App({ target: el, props });
    },
  });
}

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

No branches or pull requests

2 participants