Skip to content

Commit

Permalink
fix(remix-dev/vite): fix LiveReload component nonce prop (#8014)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Dalgleish <mark.john.dalgleish@gmail.com>
  • Loading branch information
hi-ogawa and markdalgleish authored Nov 20, 2023
1 parent df51947 commit 23a6c4c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-points-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Support `nonce` prop on `LiveReload` component in Vite dev
5 changes: 4 additions & 1 deletion integration/vite-dev-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test.describe("Vite dev", () => {
<Outlet />
</div>
<Scripts />
<LiveReload />
<LiveReload nonce="1234" />
</body>
</html>
);
Expand Down Expand Up @@ -268,6 +268,9 @@ test.describe("Vite dev", () => {
await expect(hmrStatus).toHaveText("HMR updated: yes");
await expect(input).toHaveValue("stateful");

// check LiveReload script has nonce
await expect(page.locator(`script[nonce="1234"]`)).toBeAttached();

// Ensure no errors after HMR
expect(pageErrors).toEqual([]);
});
Expand Down
3 changes: 2 additions & 1 deletion packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,8 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
`export const LiveReload = ${
viteCommand !== "serve"
} ? () => null : `,
'() => createElement("script", {',
'({ nonce = undefined }) => createElement("script", {',
" nonce,",
" dangerouslySetInnerHTML: { ",
" __html: `window.__remixLiveReloadEnabled = true`",
" }",
Expand Down

0 comments on commit 23a6c4c

Please sign in to comment.