eidellev / inertiajs-adonisjs

280 stars 17 forks source link

ssr abnormal behavior #104

Open ryzexsp opened 1 year ago

ryzexsp commented 1 year ago

thank you for your amazing job

i finished a app with your awesome package

everything work perfectly

but ssr have abnormal behavior

<Head>
<component is="script" type="application/ld+json">
      {
      "@context": "https://schema.org/",
      "@type": "Article",
      ....
      },
       "datePublished": "{{ new Date(post.created_at).toISOString().substr(0, 10) }}",
      "dateCreated": "{{ new Date(post.created_at).toISOString().substr(0, 10) }}",
      "dateModified":"{{ new Date(post.updated_at).toISOString().substr(0, 10) }}"
      }
    </component>
</Head>

this is not working and throw an error because post.updated_at or post.created_at is undefined

but this way its working

<Head>
<component is="script" type="application/ld+json">
      {
      "@context": "https://schema.org/",
      "@type": "Article",
      ....
      },
     "datePublished": "{{ new Date(JSON.parse(JSON.stringify(post)).created_at).toISOString().substr(0, 10) }}",
      "dateCreated": "{{ new Date(JSON.parse(JSON.stringify(post)).created_at).toISOString().substr(0, 10) }}",
      "dateModified":"{{ new Date(JSON.parse(JSON.stringify(post)).updated_at).toISOString().substr(0, 10) }}"
      }
    </component>
</Head>

and when i am using curl or view:source ,head retunes everything without problem

<script inertia type="application/ld+json"> {
  "@context": "https://schema.org",
  "@type": "LocalBusiness",
  ...
  "sameAs": [
    "https://t.me/blala",
    "https://www.instagram.com/blala",
    "https://twitter.com/blala"
  ]
} </script>

but when page loads in browser its change to empty script tag

<script type="application/ld+json" inertia=""></script>

exmpale site

nodejs 18.13.0

inertiajs-adonisjs 7.4.0