Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(remix-react): add timeout prop to LiveReload component #4036

Merged
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
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