inertiajs / inertia-laravel

The Laravel adapter for Inertia.js.
https://inertiajs.com
MIT License
2.08k stars 234 forks source link

BUG: Head component unexpectedly changes the `$el` passed in any method #504

Closed ericmp33 closed 1 year ago

ericmp33 commented 1 year ago

Steps to reproduce the issue:

  1. Clone this repo.
  2. Do: composer i, npm i, php artisan serve, npm run dev.
  3. Click the button that appears in the browser (component located in resources/js/Pages/Test.vue). Open the browser's console. You will notice there is 1 console log:

    
    <template>
    <Head title="Something" />
    
    <button
    @click="doStuff($el)"
    v-text="`click me`"
    class="bg-red-500 hover:bg-red-600 p-2 rounded"
    />
    </template>
![image](https://user-images.githubusercontent.com/60661635/218161696-3c6baff3-d014-4a48-bbeb-537308e63dd7.png)

4. Remove the `Head` component from the `template` (actually remove it, don't comment it). Click the button again. Now, the console log has changed!
```html
<template>
  <button
    @click="doStuff($el)"
    v-text="`click me`"
    class="bg-red-500 hover:bg-red-600 p-2 rounded"
  />
</template>

<script setup>
import { Head } from '@inertiajs/vue3'

const doStuff = $el => console.log($el)
</script>

image

So seems the Head component modifies something and makes that the elements that you pass in the functions of the template don't work fine 🤯.

ericmp33 commented 1 year ago

Seems wrapping it all inside a div makes it work. Is not an Inertia bug,

More info: https://discord.com/channels/592327939920494592/601127114288136193/1084183744484741120