Skip to content

Instantly share code, notes, and snippets.

View hanford's full-sized avatar
🌝

Jack Hanford hanford

🌝
View GitHub Profile
/* eslint-enable no-param-reassign */
function genId() {
const num = uuid();
return `graphql__${num}`;
}
function uuid() {
return 'xxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (Math.random() * 16) | 0,
// ReactDOMServer doesn't currently support React.Suspense which is a problem for us
// as Next.js uses ReactDOMServer. So by us using components/Suspense instead of React.Suspense
// we can work around this limitation by just returning the fallback instead of the Suspense boundary
import { Suspense } from 'react';
import { isBrowserEnvironment } from 'utils/constants';
function LatticeSuspense(props: React.SuspenseProps): JSX.Element {
if (typeof props.fallback === 'undefined') {
throw new Error('LatticeSuspense requires fallback prop!');
/test-page
Before: 1.9mb
After: 345kb
_app
Before: 4.0mb
After: 3.0mb
Savings: 1.0mb
@hanford
hanford / date-fns-tz+1.1.3.patch
Created May 31, 2021 18:49
Correct ESM implementation in date-fns-tz 1.1.3
diff --git a/node_modules/date-fns-tz/esm/.DS_Store b/node_modules/date-fns-tz/esm/.DS_Store
new file mode 100644
index 0000000..e69de29
diff --git a/node_modules/date-fns-tz/esm/_lib/tzIntlTimeZoneName/index.js b/node_modules/date-fns-tz/esm/_lib/tzIntlTimeZoneName/index.mjs
similarity index 100%
rename from node_modules/date-fns-tz/esm/_lib/tzIntlTimeZoneName/index.js
rename to node_modules/date-fns-tz/esm/_lib/tzIntlTimeZoneName/index.mjs
diff --git a/node_modules/date-fns-tz/esm/_lib/tzParseTimezone/index.js b/node_modules/date-fns-tz/esm/_lib/tzParseTimezone/index.mjs
similarity index 98%
rename from node_modules/date-fns-tz/esm/_lib/tzParseTimezone/index.js
@hanford
hanford / date-fns+2.18.0.patch
Last active May 31, 2021 18:48
Correct ESM implementation in date-fns 2.18.0
diff --git a/node_modules/date-fns/esm/_lib/addLeadingZeros/index.js b/node_modules/date-fns/esm/_lib/addLeadingZeros/index.mjs
similarity index 100%
rename from node_modules/date-fns/esm/_lib/addLeadingZeros/index.js
rename to node_modules/date-fns/esm/_lib/addLeadingZeros/index.mjs
diff --git a/node_modules/date-fns/esm/_lib/assign/index.js b/node_modules/date-fns/esm/_lib/assign/index.mjs
similarity index 100%
rename from node_modules/date-fns/esm/_lib/assign/index.js
rename to node_modules/date-fns/esm/_lib/assign/index.mjs
diff --git a/node_modules/date-fns/esm/_lib/cloneObject/index.js b/node_modules/date-fns/esm/_lib/cloneObject/index.mjs
similarity index 100%
.....
// we're using normalizeNode to automatically detect/insert links as the user types
editor.normalizeNode = entry => {
const [node, path] = entry;
// because normalizeNode is recursive, we need to guard against two cases.
// 1. Ensure we're operating on a leaf node (Text.isText)
// 2. Ensure that our parent isn't a link. (Otherwise this function is called infinite times)
const isText = Text.isText(node);
export default function plugin(settings = {}) {
this.Compiler = compiler;
function compiler(node) {
return node.children.map(markdownToSlate);
}
}
function markdownToSlate(node) {
let children = [];
export default function parseToMarkdown(chunk) {
let children = !chunk.type
? chunk.text
: chunk.children.map(c => parseToMarkdown({ ...c, parentType: chunk.type })).join('');
if (children === '') return;
// formatting
if (chunk.bold) {
children = `**${children.trim()}** `;
const parseGitLog = require('parse-git-log');
const isBefore = require('date-fns/isBefore');
const subBusinessDays = require('date-fns/subBusinessDays');
const parseISO = require('date-fns/parseISO');
const twoWeeksAgo = subBusinessDays(new Date(), 10);
const commits = [];
parseGitLog()
import { useLazyLoadQuery, graphql } from "react-relay/hooks";
import Link from "next/link";
import { PersonalPageQueryResponse } from "../__generated__/PersonalPageQuery.graphql";
export default function PersonalPage() {
const data = useLazyLoadQuery<PersonalPageQueryResponse>(
graphql`
query PersonalPageQuery {
viewer {
user {