inertia-laravel icon indicating copy to clipboard operation
inertia-laravel copied to clipboard

Ability to add class to @inertia directive

Open nurdism opened this issue 3 years ago • 6 comments

This implements #370

nurdism avatar Mar 25 '22 20:03 nurdism

@reinink is there something about this PR that is incorrect?

nurdism avatar May 11 '22 17:05 nurdism

Hey! So I really like this PR, but the only issue is it's broken when running Inertia in SSR, since we recreate the wrapper div#app element in SSR:

Vue 3: https://github.com/inertiajs/inertia/blob/master/packages/inertia-vue3/src/createInertiaApp.js#L30-L36 React: https://github.com/inertiajs/inertia/blob/master/packages/inertia-react/src/createInertiaApp.js#L28-L33

If we're going to do this, we'll need to find a way to make that work first.

reinink avatar May 17 '22 13:05 reinink

Ahh I see, what about this approach?

https://github.com/nurdism/inertia-laravel/blob/issue-370/src/Directive.php https://github.com/nurdism/inertia/blob/issue-370-patch-1/packages/inertia-vue3/src/createInertiaApp.js

I'm not very familiar with react ssr, not sure how to pass the classes string to the createElement function.

nurdism avatar May 25 '22 19:05 nurdism

I just realized this doesn't work if you use the compileHead function, but maybe this could be added to the inertia config and do the same thing.

nurdism avatar May 25 '22 20:05 nurdism

I've added a config option 'app' that allows you to pass 'classes' string from it, the @inertia directive should function normally w/o any added prams, it defaults to input, then config and then the standard 'app' and reads the classes string directly from the config.

With the ssr request it modifies the $page and adds 'classes' to the request, it pulls the classes string from the config. That can then be picked up and passed the createElement or h function.

Let me know if you have any questions or concerns

nurdism avatar May 25 '22 21:05 nurdism

@reinink is this PR ever getting merged or is this something I should just add to my project manually instead?

mysticseagull avatar Sep 27 '22 00:09 mysticseagull