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

Make <Scripts> render nothing on the client #390

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- mcansh
- developit
18 changes: 15 additions & 3 deletions packages/remix-react/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -672,15 +672,25 @@ type ScriptProps = Omit<
| "suppressHydrationWarning"
>;

export const Scripts =
typeof window === "undefined" ? ServerScripts : ClientScripts;

/**
* Browser implementation of <Scripts>, which does nothing.
*/
function ClientScripts(props: ScriptProps) {
return null;
}

/**
* Renders the `<script>` tags needed for the initial render. Bundles for
* additional routes are loaded later as needed.
* Server implementation of <Scripts>, which renders the `<script>` tags needed
* for the initial render. Bundles for additional routes are loaded later as needed.
*
* @param props Additional properties to add to each script tag that is rendered.
* In addition to scripts, \<link rel="modulepreload"> tags receive the crossOrigin
* property if provided.
*/
export function Scripts(props: ScriptProps) {
function ServerScripts(props: ScriptProps) {
let {
manifest,
matches,
Expand All @@ -690,6 +700,8 @@ export function Scripts(props: ScriptProps) {
} = useRemixEntryContext();

let initialScripts = React.useMemo(() => {
// if (typeof document !== 'undefined') return null;

let contextScript = serverHandoffString
? `window.__remixContext = ${serverHandoffString};`
: "";
Expand Down