Skip to content

Commit

Permalink
feat(remix-react): add timeout prop to LiveReload component (#4036)
Browse files Browse the repository at this point in the history
Co-authored-by: Pedro Cattori <pcattori@gmail.com>
  • Loading branch information
joelazar and pcattori authored Jan 23, 2023
1 parent f8000db commit ec3f3aa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/wild-foxes-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"remix": patch
"@remix-run/react": patch
---

Configure the browser-side live reload socket timeout via the new `timeoutMs` prop on `<LiveReload />`
8 changes: 8 additions & 0 deletions packages/remix-react/__tests__/components-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ describe("<LiveReload />", () => {
"let port = (window.__remixContext.dev && window.__remixContext.dev.liveReloadPort) || 1234;"
);
});

it("timeout of reload is set to 200ms", () => {
LiveReload = require("../components").LiveReload;
let { container } = render(<LiveReload timeoutMs={200} />);
expect(container.querySelector("script")).toHaveTextContent(
"setTimeout( () => remixLiveReloadConnect({ onOpen: () => window.location.reload(), }), 200 );"
);
});
});
});

Expand Down
4 changes: 3 additions & 1 deletion packages/remix-react/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1536,9 +1536,11 @@ export const LiveReload =
? () => null
: function LiveReload({
port = Number(process.env.REMIX_DEV_SERVER_WS_PORT || 8002),
timeoutMs = 1000,
nonce = undefined,
}: {
port?: number;
timeoutMs?: number;
/**
* @deprecated this property is no longer relevant.
*/
Expand Down Expand Up @@ -1582,7 +1584,7 @@ export const LiveReload =
remixLiveReloadConnect({
onOpen: () => window.location.reload(),
}),
1000
${String(timeoutMs)}
);
}
};
Expand Down

0 comments on commit ec3f3aa

Please sign in to comment.