Skip to content

Instantly share code, notes, and snippets.

View dac09's full-sized avatar

Daniel Choudhury dac09

View GitHub Profile
@dac09
dac09 / buildForStreamingServer.ts
Created March 17, 2024 14:04
How I modified the streaming server to build with client conditions and "redirect" server imports.
import fs from 'node:fs'
import path from 'node:path'
import { build as viteBuild } from 'vite'
import { cjsInterop } from 'vite-plugin-cjs-interop'
import { getPaths } from '@redwoodjs/project-config'
export async function buildForStreamingServer({
verbose = false,
@dac09
dac09 / ExampleServer.mjs
Last active February 16, 2024 11:08
ExampleServer.mjs
// @ts-check
import express from 'express'
import { createServer as createViteServer } from 'vite'
import { renderToPipeableStream, renderToString } from 'react-dom/server'
import { PassThrough, Writable } from 'node:stream'
import React from 'react'
async function createServer() {
const app = express()
@dac09
dac09 / fakegen.js
Last active January 8, 2024 11:58
Fake generate files test to see api server dev restart time
// To access your database
// Append api/* to import from api and web/* to import from web
import http from 'http'
import { performance } from 'perf_hooks'
import { db } from 'api/src/lib/db'
const fs = require('fs')
const path = require('path')
@dac09
dac09 / createSuspendingCell.tsx
Last active August 24, 2023 09:25
Using useBgQuery and useReadQuery to construct a Redwood Cell
import { QueryReference, UseBackgroundQueryResult, useBackgroundQuery, useReadQuery } from "@apollo/client"
import type { DocumentNode } from "graphql"
import { Suspense } from "react"
import { CellErrorBoundary } from "./CellErrorBoundary.tsx"
interface Cell {
QUERY: DocumentNode,
Success: React.FC,
Loading: React.FC,
Failure: React.FC,
@dac09
dac09 / Setup Apollo Streaming.md
Last active August 29, 2023 08:25
Script to setup experimental Apollo with streaming and ssr

Run this on the root of your Redwood project, like this:

npx https://gist.github.com/dac09/99cf500bbd5dc740a10c8cabf7372018
@dac09
dac09 / Find SVG Usage.md
Last active August 23, 2023 15:05
Find all usages of SVG imports in web/src

Usage

If you're in the folder where you want to do a search:

npx https://gist.github.com/dac09/658e792266b416fad7957dd83b523ee2

Or if you want to search a specific directory.

@dac09
dac09 / babel.config.js
Created November 16, 2021 15:03
Babel plugin for debugging
const template = require('@babel/template').default
module.exports = {
plugins: [
[
function debugPlugin({ types }) {
return {
name: 'debug-plugin',
visitor: {
Program(p, options) {
import { contacts } from './contacts'
import type { StandardScenario } from './contacts.scenarios'
import { setContext } from '@redwoodjs/graphql-server'
const MOCKED_USER = {
id: 156,
name: 'Danny',
}
@dac09
dac09 / .npmrc
Created August 31, 2021 13:48
Configure github npm registry
@tapehq:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=PERSONAL_TOKEN_WITH_READ_PACKAGE
@dac09
dac09 / 1. What Is this?.md
Last active August 6, 2021 18:53
Babel debugging plugin

Put this plugin after the plugin you're debugging to see how it transformed your code.