Skip to content

Instantly share code, notes, and snippets.

@kiliman
kiliman / env.server.ts
Last active March 10, 2023 19:34
Use zod to parse/validate environment variables
import { z } from 'zod';
import { getParams } from './params';
const envSchema = z.object({
NODE_ENV: z.string(),
DATABASE_URL: z.string().url(),
SESSION_SECRET: z.string(),
AUTH_SECRET: z.string(),
ENABLE_REGISTRATION: z.boolean().default(false),
SMTP_HOST: z.string(),
@kiliman
kiliman / @remix-run+react+1.7.5.patch
Created November 10, 2022 00:35
Patches for Remix to resolve issues with `index` route handling
diff --git a/node_modules/@remix-run/react/dist/esm/components.js b/node_modules/@remix-run/react/dist/esm/components.js
index e884e7b..56ddff4 100644
--- a/node_modules/@remix-run/react/dist/esm/components.js
+++ b/node_modules/@remix-run/react/dist/esm/components.js
@@ -746,6 +746,7 @@ FormImpl.displayName = "FormImpl";
*/
function useFormAction(action, // TODO: Remove method param in v2 as it's no longer needed and is a breaking change
method = "get") {
+ let { manifest }= useRemixEntryContext()
let {
@kiliman
kiliman / README.md
Created October 13, 2022 15:06
Patch to backport React Router "non-alphanumeric route prefix" fix to Remix

Patch bug in React Router 6.3

This is a backport of React Router PR #9300 to React Router 6.3 which is the version pinned in Remix.

This fix allows non-alphanumeric characters to start a route path. This means /@user or /.well-known/ or even /😍 will work.

Currently this only patches the development build as the production files are minified. I will update the patch once I setup to build React Router locally.

@kiliman
kiliman / @remix-run+react+1.7.2.patch
Created October 11, 2022 20:08
Patch to fix button formMethod support
diff --git a/node_modules/@remix-run/react/dist/components.js b/node_modules/@remix-run/react/dist/components.js
index 26189ce..9210ce0 100644
--- a/node_modules/@remix-run/react/dist/components.js
+++ b/node_modules/@remix-run/react/dist/components.js
@@ -737,7 +737,6 @@ let FormImpl = /*#__PURE__*/React__namespace.forwardRef(({
event.preventDefault();
let submitter = event.nativeEvent.submitter;
submit(submitter || event.currentTarget, {
- method,
replace
@kiliman
kiliman / remix-example
Created July 24, 2022 17:34
Shell script to download Remix example from GitHub without having to clone entire repo
#! /usr/bin/env bash
if [ -z "$1" ]; then
echo USAGE: "$0" EXAMPLE
exit
fi
url="https://github.com/remix-run/remix/examples/$1"
# default to branch master
branch=main
@kiliman
kiliman / relative-path.ts
Last active July 20, 2022 17:49
Remix relative paths
function useRelativePath() {
const location = useLocation()
const base = new URL(`http://dummy${location.pathname}${location.search}`)
return (relativePath: string) => {
const relative = new URL(relativePath, base)
return `${relative.pathname}${relative.search}`
}
}
// path = /parent/child/?a=1
@kiliman
kiliman / remix.ts
Created July 16, 2022 15:19
Remix re-export with superjson
import { useActionData, useLoaderData } from "@remix-run/react";
import * as _superjson from "superjson";
export {
AbortController,
createCookie,
createCookieSessionStorage,
createFileSessionStorage,
createMemorySessionStorage,
createReadableStreamFromReadable,
@kiliman
kiliman / email.server.tsx
Last active July 15, 2022 17:45
Send email from Remix using `nodemailer`
import type { Transporter } from 'nodemailer'
import nodemailer from 'nodemailer'
import Mail from 'nodemailer/lib/mailer'
declare global {
var transport: Transporter
}
const transporter: Transporter =
global.transport ?? (global.transport = getTransport())
function getTransport() {
@kiliman
kiliman / updateremix.sh
Created July 15, 2022 13:59
Update Remix packages
#!/usr/bin/env bash
npm outdated | grep -Eo '@remix-run/[-a-z]+' | uniq | xargs npm up
@kiliman
kiliman / getRelativePath.ts
Created July 11, 2022 16:00
Function to generate relative URL paths
function getRelativePath(location: Location, relativePath: string) {
const base = new URL(`http://dummy${location.pathname}${location.search}`)
const relative = new URL(relativePath, base)
return `${relative.pathname}${relative.search}`
}
// path = /parent/child/?a=1
const location = useLocation()
const relative = getRelativePath(location, '..?b=2')
// relative = /parent/?b=2