github blitz-js/blitz v0.30.0
v0.30.0 OFFICIAL BETA

latest releases: v2.0.8, blitz@2.0.8, @blitzjs/rpc@2.0.8...
3 years ago

Enjoy 😎 — also check out our brand new website! 👉 http://blitzjs.com/

💥 Breaking Changes

  • You must use the new enhancePrisma() utility: #1720, #1762
    • This allows importing Prisma enum's into your client build
    • It ensures a single prisma instance in your app
    • It adds db.$reset() for use in testing
    • Read the docs
+import { enhancePrisma } from "blitz"
import { PrismaClient } from "@prisma/client"
export * from "@prisma/client"

-let prisma: PrismaClient
-if (serverEnv.isProduction) {
-  prisma = new PrismaClient()
-} else {
-  // Ensure the prisma instance is re-used during hot-reloading
-  // Otherwise, a new client will be created on every reload
-  globalThis["prisma"] = globalThis["prisma"] || new PrismaClient()
-  prisma = globalThis["prisma"]
-}
-export default prisma
+const EnhancedPrisma = enhancePrisma(PrismaClient)
+export default new EnhancedPrisma()
  • Prefix all ctx.session methods with $ and move publicData fields to top level of ctx.session: #1779
-ctx.session.authorize()
+ctx.session.$authorize()
const userId = ctx.session.userId
-const orgId = ctx.session.publicData.orgId
+const orgId = ctx.session.orgId
  • Simplify type definition for PublicData AND add strong typing for $isAuthorized() and $authorize(): #1806, #1796
-import { DefaultCtx, SessionContext, DefaultPublicData } from "blitz"
+import { DefaultCtx, SessionContext } from "blitz"
+import { SimpleRolesIsAuthorized } from "@blitzjs/server"
import { User } from "db"

+// Note: You should switch to Postgres and then use a DB enum for role type
+export type Role = "ADMIN" | "USER"

declare module "blitz" {
  export interface Ctx extends DefaultCtx {
    session: SessionContext
  }
-  export interface PublicData extends DefaultPublicData {
-    userId: User["id"]
-  }
+  export interface Session {
+    isAuthorized: SimpleRolesIsAuthorized<Role>
+    PublicData: {
+      userId: User["id"]
+      roles: Role
+    }
+  }
}
  • Change session cookies to have a unique prefixed based on package.json name field: #1743
    • This is not a breaking code change, but it will force all users to be logged out (they can simply log back in and continue on)
  • Change blitz generate to generate all pages in app/pages/ and update new app structure with app/core/: #1719
  • Change blitz start to blitz dev and blitz start --production to blitz start: #1872
  • Change useSession to use suspense by default: #1888
    • You now need to ensure useSession has a <Suspense> component above it in the tree
    • You can use useSession({suspense: false}) to disable it
    • Suspense disabled if you are using reactMode: 'legacy'
  • Change blitz generate default syntax from default[value] to default=value: #1906

🚀 New Features

  • 🎉 Add Forgot Password code to new app template: #1127
    • You can add this to existing apps like this:
      • Upgrade global blitz install to this version
      • Run blitz new your-existing-app. It will add new files and for existing files, it will show changes and ask what you want to do
  • Add resolver.pipe(), resolver.zod(), and resolver.authorize() for queries/mutations: #1801
import {resolver} from "blitz"
import db from "db"
import * as z from "zod"

export const CreateProject = z.object({
  name: z.string(),
  dueDate: z.date().optional(),
  orgId: z.number().optional(),
})

export default resolver.pipe(
  resolver.zod(CreateProject),
  resolver.authorize(),
  // Set default orgId
  (input, {session}) => ({...input, orgId: input.orgId ?? session.orgId}),
  async (input, ctx) => {
    return await db.project.create({data: input})
  },
)
  • Add blitz/babel preset which includes babel-plugin-superjson-next for getServerSideProps Date serialization: #1771
// babel.config.js
module.exports = {
-  presets: ["next/babel"],
+  presets: ["blitz/babel"],
  plugins: [],
}
  • Drastically simplify eslint integration with new eslint-config-blitz package: #1749
// .eslintrc.js
module.exports = {
-   env: {
-     es2020: true,
-   },
-   extends: ['react-app', 'plugin:jsx-a11y/recommended'],
-   plugins: ['jsx-a11y'],
-   rules: {
-     "import/no-anonymous-default-export": "error",
-     'import/no-webpack-loader-syntax': 'off',
-     'react/react-in-jsx-scope': 'off', // React is always in scope with Blitz
-     'jsx-a11y/anchor-is-valid': 'off', //Doesn't play well with Blitz/Next <Link> usage
-   },
+   extends: ["blitz"],
 }

// package.json
-     "@typescript-eslint/eslint-plugin": "4.x",
-     "@typescript-eslint/parser": "4.x",
-     "babel-eslint": "10.x",
-     "eslint-config-react-app": "6.x",
-     "eslint-plugin-flowtype": "5.x",
-     "eslint-plugin-import": "2.x",
-     "eslint-plugin-jsx-a11y": "6.x",
-     "eslint-plugin-react": "7.x",
-     "eslint-plugin-react-hooks": "4.x",
  • Drastically simplify Jest integration with a Blitz jest preset and by moving test dependencies into blitz.: #1725
    • You can remove import "@testing-library/jest-dom/extend-expect" from test/setup.ts
    • You can remove test/__mocks__/fileMock.js
// jest.config.js
-const { pathsToModuleNameMapper } = require("ts-jest/utils")
-const { compilerOptions } = require("./tsconfig")
 module.exports = {
-   // Test setup file
-   setupFilesAfterEnv: ["<rootDir>/test/setup.ts"],
-  // ... LOTS of stuff
-   collectCoverageFrom: ["**/*.{js,jsx,ts,tsx}", "!**/*.d.ts", "!**/node_modules/**"],
+   preset: "blitz",
 }

// package.json
-     "@testing-library/jest-dom": "5.x",
-     "@testing-library/react": "11.x",
-     "@testing-library/react-hooks": "3.x",
-     "@types/jest": "26.x",
-     "jest": "26.x",
-     "jest-environment-jsdom-fourteen": "1.x",
-     "jest-watch-typeahead": "0.x",
-     "react-test-renderer": "17.x",
-     "ts-jest": "26.x"
  • Change blitz generate to generate all pages in app/pages/ instead of app/modelName/pages/: #1719
  • Improvements to isAuthorized adapters: #1796
    • Ability to strongly type
    • Change first arg to have ctx
    • Allow multiple params
    • Read the docs
  • 🎉 Add page.authenticate, page.redirectAuthenticatedTo, and page.suppressFirstRenderFlicker: #1901
  • Add generateToken() and hash256() utilities: #1721
  • Update blitz generate templates for Prisma 2.15 AND update newapp/examples to Prisma 2.15: #1759
  • Change normal resolver logging to log serializer duration: #1778
  • Add blitz generate mutation: #1871
  • Massive update to blitz generate templates to generate production ready code: #1870
  • Add paginate resolver utility and add it to blitz generate template: #1199
  • Add SimpleRolesIsAuthorized&lt;RoleType&gt; type so session.$authorize() can type check the roles AND update new app template accordingly: #1883
  • Add initialPublicData option to useSession for use with SSR: #1807
  • Automatically prompt to run prisma migrate after blitz generate: #1894
  • Add useAuthorize and useRedirectAuthenticated hooks: #1900
  • Remove requirement of publicData.roles, change new app to use publicData.role, and fix public data types: #1788
  • Add useAuthenticatedSession() hook and fix publicData types for authenticated sessions: #1910
  • Automatically clear console on blitz dev (can disable with cli.clearConsoleOnBlitzDev = false in blitz.config.js: #1909
  • Change blitz generate delete mutation to use db.deleteMany instead of db.delete: #1924

🐞 Patches

  • Fix blitz generate bug when model name ends with number: #1727
  • Add .yalc folder to ignore paths: #1734
  • Automatically disable useQuery suspense when not using concurrent mode: #1735
  • Fix all queries not being refetched on login: #1748
  • Update dependencies (2021-01-19): #1736
  • Fix logging issues: Update tslog: 3.0.5 → 3.1.0: #1760
  • Fix relative imports from within API routes: #1761
  • Fix API duration log to include serialization time AND add log serialization duration at DEBUG log level: #1765
  • Fix prisma errors missing code & meta properties: #1766
  • Add missing type exports like GetStaticPropsContext: #1772
  • Major improvement to blitz install UX: #1782
  • Fix not all folder names kebab-case from blitz generate: #1790
  • Fix blitz console not working in vanilla JS projects: #1686
  • Fix to properly handle http errors (no more Failed to parse json from request to /api/users/queries/getCurrentUser): #1808
  • Fix new app and blitz generate templates to use new session.$ prefix: #1810
  • Fix blitz install error message when recipe doesn't exist: #1815
  • Fix several compiler bugs like ENOENT, file rename broken, default export not component, etc: #1835
  • Update all dependencies (2021-02-01): #1839
  • Fix blitz new for people without global git config: #1847
  • Upgrade superjson: 1.5.2 → 1.6.0: #1854
  • Upgrade next: 10.0.5 → 10.0.6 and refactor runtime require statements: #1828
  • Update all Yarn dependencies (2021-02-08): #1886
  • Fix useSession return type to have userId: number | null: #1895
  • Fix useQuery hooks return type when enabled or suspense could be false: #1893
  • Upgrade superjson: 1.6.0 → 1.6.2: #1904
  • Fix error message grammar: 3114e8b
  • Fix type of options for useQuery hooks: #1913
  • Fix query cache being deleted on login instead of being invalidated: #1917
  • Remove all unneeded imports of React from templates: #1925
  • Unify blitz build folder. Now .blitz/build is always used instead of .blitz/caches/dev or .blitz/caches/build: #1930
  • Hopefully fix Windows EPERM , EBUSY, ENOTEMPTY, ENOENT errors: #1931
  • Fix file paths in blitz server logs to be the original path instead of compiled path: #1933
  • Fix type issue in blitz generate code: #1941
  • Fix getQueryKey() to work on the server: #1624
  • Upgrade prisma to 2.17: #1951
  • Update tslog to version 3.1.1: #1853

⚡️ Changes to the New App Template

  • Remove app/auth/auth-utils.ts by moving code into the login mutation: #1740
  • Add changePassword mutation: #1741
  • 🎉 Add Forgot Password code to new app template: #1127
  • Update &lt;Form&gt; to easily hide default submit button by making submitText optional: #1800
  • fix PublicData typo in types.ts: 4ec37a5
  • Fix typo in resetPassword.test.ts - create => $create: ac55bc4
  • update mutations to use the new pipe functions: #1811
  • update _app.tsx to use new ErrorFallbackProps for better typing: #1833
  • small tweak to error fallback in _app.tsx: d1c4553
  • Add legacy-peer-deps to .npmrc for npm v7 compatibility: #1859
  • upgrade prisma to 2.16 and change @prisma/cli to new prisma name: #1864
  • fix react-hook-form reset password page: #1902
  • remove browserslist from package.json because it only affects CSS: #1928
  • add types.d.ts with type declarations for CSS/SCSS modules: #1929

👩‍🍳 Recipes

  • Remove console.log from reflexjs recipe: #1722
  • Add Quirrel recipe AND add Plain-Text Transformer to recipe APIs: #1764
  • add gh-action-yarn-postgres recipe which adds a production github action config: #1876

Internal Meta Changes

  • Add @malkomalko as L1 Maintainer: #1728
  • Docs: add tarunama as a contributor: #1739
  • Docs: add bacongravy as a contributor: #1742
  • Add @mikeesto as a contributor: 04ed495
  • Add @marina-ki as a contributor: e5baf8c
  • Lori retires as L1 maintainer: 817b760
  • fix some code formatting: d69ca33
  • Change package.json engines version 12.20 to 12: #1773
  • Retry example e2e tests one time if they fail: f61ae6e
  • Docs: Add READMEs to packages that were missing them: #1780
  • Add prisma issue to new issue page: 25811cf
  • Change all references/links to Slack over to our new Discord: bbec590
  • Add @jonasthiesen as a contributor: 8d2e7ab
  • Update all dependencies (2021-01-25): #1792
  • Docs: add marina-ki as a contributor: #1797
  • Docs: add thakkaryash94 as a contributor: #1798
  • Docs: add rince as a contributor: #1825
  • Add @queq1890 as a contributor: 7195aae
  • Docs: add Gim3l as a contributor: #1849
  • Docs: add akbo as a contributor: #1851
  • Docs: add ajmarkow as a contributor: #1852
  • Docs: add wafuwafu13 as a contributor: #1861
  • Docs: add merodiro as a contributor: #1862
  • Add @lcswillems as a contributor: 7804d3e
  • Add cypress for e2e cli testing: #1846
  • Update auth example project pages from latest templates: f405b5b
  • Docs: add alii as a contributor: #1882
  • Docs: add lcswillems as a contributor: #1892
  • Docs: add rodrigoehlers as a contributor: #1896
  • Add internal BlitzAppRoot component: #1898
  • Docs: add mtford90 as a contributor: #1899
  • Docs: add LBrian as a contributor: #1903
  • Add @beerose as a contributor: b238bae
  • Docs: add JuanM04 as a contributor: #1911
  • Docs: add JuanM04 as a contributor: #1912
  • Add @arenddeboer as a contributor: 42bf665
  • Add node 15 to CI test matrix: #1927
  • Flavio retires from L1 maintainer: 5697173
  • Add @fmilani as a contributor: 5f6d296
  • Docs: add jxe as a contributor: #1946
  • Chore: unify spell of TypeScript: #1731

Credits

Huge thanks to @mtford90, @sandulat, @engelkes-finstreet, @camilo86, @Kosai106, @JuanM04, @koolii, @malkomalko, @bacongravy, @hasparus, @marina-ki, @Flavyoo, @rince, @akbo, @alii, @lcswillems, @rodrigoehlers, @LBrian, @jxe, @scisteffan, @merodiro, @Skn0tt, @nitaking, @MrLeebo, @wafuwafu13, and @tarunama for helping!

Don't miss a new blitz release

NewReleases is sending notifications on new releases.