Skip to content

Instantly share code, notes, and snippets.

View eric-burel's full-sized avatar
Writing courses at nextjspatterns.com

Eric Burel eric-burel

Writing courses at nextjspatterns.com
View GitHub Profile
@eric-burel
eric-burel / next-app-router-bleeding-edge.md
Created June 23, 2023 07:03
next-app-router-bleeding-edge
  • Can't mix static layout and dynamic pages, this prevents define common static data requirements in the layout and then optionnally dynamic requirements in some pages below: vercel/next.js#44712 (comment)

  • RSC might be a way to colocate graphql data requirements with components, but it's not very declarative

  • i18n: since "FormattedMessage" tend to be a leaf component, we can't really server-side render it, all i18n messages thus need hydration

  • 404 are delicate because route handlers can be mixed with routes : vercel/next.js#49696, and also when fetching files (you may conflate a file with the first route parameter of your app eg [lang])

const {EditorState} = require("prosemirror-state")
const {EditorView} = require("prosemirror-view")
const {Schema, DOMParser} = require("prosemirror-model")
const {schema} = require("prosemirror-schema-basic")
const {addListNodes} = require("prosemirror-schema-list")
const {exampleSetup} = require("prosemirror-example-setup")
const { inputRules, InputRule } = require("prosemirror-inputrules")
const starRule = new InputRule(/\*(.+)\*/, (state, match, start, end) => {
@eric-burel
eric-burel / mockDbClient.ts
Last active August 30, 2023 09:41
A mock database client that counts the opened connections and store data into $HOME/.mockdb
import fs from "fs";
import os from "os";
import path from "path";
const fsPromises = fs.promises;
// DATA STORE
// In a real project this belongs to the db server code
// We simulate a distant db by storing data in a file
const filePath = path.resolve(os.homedir(), ".mockdb");
async function updateData<TData=any>(data:TData) {
@eric-burel
eric-burel / generateTocFromSections.js
Created July 11, 2022 15:44
Generate toc from sections a Slidev app - to be included in your index.html
/**
* Run this script manually in the console and copy-paste the result to generate
* a TOC based on "section" layout, instead of markdown titles (that are not helpful here)
*
* NOTE: this script is loaded in index.html,
* so you can call generateTocFromSections easily from the slidev app, in the browser console
*
* NOTE: this could also be adapted with Cheerio or an HTML/md parser to parse the markdown directly?
*/
function generateTocFromSections() {
const edits = [
[
"node_modules/ts-invariant/package.json",
{
type: "module",
exports: {
".": "./lib/invariant.esm.js",
"./process/index.js": "./process/index.js",
},
},
@eric-burel
eric-burel / useWarnOnUnsaved.ts
Created May 21, 2021 09:18
Hook to warn user on unwanted page leave
import { useIntlContext } from "@vulcanjs/i18n";
import { useEffect, useRef } from "react";
import { block } from "./block";
import debug from "debug";
const debugTransitions = debug("vn:route-transition");
/**
* Can trigger an alert on unsaved changes
*
* @see https://github.com/ReactTraining/history/blob/master/docs/blocking-transitions.md
@eric-burel
eric-burel / nextConfigDefinePlugin.js
Created February 26, 2021 08:13
Next webpack DefinePlugin
// in next.config.js Webpack field
config.plugins.push(
new options.webpack.DefinePlugin({
  'process.env.NEXT_IS_SERVER': JSON.stringify(options.isServer.toString()),
  })
)
@eric-burel
eric-burel / nextConfigPackageVersion.js
Created February 26, 2021 08:09
next config public app
// in next.config.js
import packageJson from "./package.json"
module.exports = {
env: {
NEXT_PUBLIC_APP_VERSION: packageJson.version
}
}
import snakeCase from 'lodash/snakeCase';
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import fs from 'fs';
let bound;
if (Meteor.isServer) {
bound = Meteor.bindEnvironment(callback => callback());
}
// Package 1 - "my-basic-ui"
const MyBasicButton = ({onClick, children}) => (
<button onClick={onClick}>
{children}
</button>
)
// Tell other packages they can use your component
// under the name "Button"
registerComponent({
name: 'Button',