Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react/src/createInertiaApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default async function createInertiaApp<SharedProps extends PageProps = P
createElement('script', {
'data-page': id,
type: 'application/json',
dangerouslySetInnerHTML: { __html: JSON.stringify(initialPage) },
dangerouslySetInnerHTML: { __html: JSON.stringify(initialPage).replace(/\//g, '\\/') },
}),
createElement('div', { id }, reactApp as ReactElement),
)
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/createInertiaApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default async function createInertiaApp<SharedProps extends PageProps = P

return {
body: useScriptElementForInitialPage
? `<script data-page="${id}" type="application/json">${JSON.stringify(initialPage)}</script><div data-server-rendered="true" id="${id}">${html}</div>`
? `<script data-page="${id}" type="application/json">${JSON.stringify(initialPage).replace(/\//g, '\\/')}</script><div data-server-rendered="true" id="${id}">${html}</div>`
: `<div data-server-rendered="true" id="${id}" data-page="${escape(JSON.stringify(initialPage))}">${html}</div>`,
head: [head, css ? `<style data-vite-css>${css.code}</style>` : ''],
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3/src/createInertiaApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default async function createInertiaApp<SharedProps extends PageProps = P
h('script', {
'data-page': id,
type: 'application/json',
innerHTML: JSON.stringify(initialPage),
innerHTML: JSON.stringify(initialPage).replace(/\//g, '\\/'),
}),
h('div', {
id,
Expand Down
2 changes: 1 addition & 1 deletion tests/app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ app.get('/ssr/page-with-script-element', (req, res) =>
inertia.renderSSR(req, res, {
component: 'SSR/PageWithScriptElement',
props: {
message: 'Hello from script element!',
message: 'Hello from script element! Escape </script>.',
},
}),
)
Expand Down
4 changes: 2 additions & 2 deletions tests/ssr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ test.describe('SSR', () => {

expect(html).toContain('data-page="app"')
expect(html).toContain('<script data-page="app" type="application/json">')
expect(html).toContain('Hello from script element!')
expect(html).toContain('Hello from script element! Escape <\\/script>.')

await page.goto('/ssr/page-with-script-element')
const scriptContent = await page.locator('script[data-page="app"]').textContent()
expect(JSON.parse(scriptContent || '')).toMatchObject({
component: 'SSR/PageWithScriptElement',
props: {
message: 'Hello from script element!',
message: 'Hello from script element! Escape </script>.',
},
})
})
Expand Down