1
0
mirror of synced 2026-02-03 18:01:02 -05:00

Compare commits

...

20 Commits

Author SHA1 Message Date
Fran Zekan
0b17d0779d Cleanup 2023-01-15 22:57:58 +01:00
Fran Zekan
b5d2b3cd95 Merge branch 'main' into feature/add-revalidate-page-to-mutations 2023-01-15 22:55:13 +01:00
Fran Zekan
8abf24e93c Fix flaky test 2022-09-30 19:51:58 +02:00
Fran Zekan
5d0e426f23 Make sure that you can't autocomplete revalidatePage in getStaticProps 2022-09-30 19:51:24 +02:00
Fran Zekan
31a1f2c959 Change cast to NextRouter from any 2022-09-30 19:31:01 +02:00
Fran Zekan
1ba606dda2 Fix lock 2022-09-30 19:25:33 +02:00
Fran Zekan
5142c04fc1 Format 2022-09-30 17:21:00 +02:00
Fran Zekan
d017699b28 Move next revalidate middleware from blitz core to blitz-next 2022-09-30 17:20:45 +02:00
Fran Zekan
2c088ce199 Remove ts annotation 2022-09-30 17:14:32 +02:00
Fran Zekan
a8046e604a Merge branch 'main' into feature/add-revalidate-page-to-mutations 2022-09-30 15:10:46 +02:00
Fran Zekan
00b64c402f Some cleanup 2022-07-30 19:59:23 +02:00
Fran Zekan
0e33972bc0 Fix start commands 2022-07-30 19:50:28 +02:00
Fran Zekan
25ebbbe77b Merge branch 'main' into feature/add-revalidate-page-to-mutations 2022-07-30 19:47:10 +02:00
Fran Zekan
6856e832e5 Merge branch 'main' into feature/add-revalidate-page-to-mutations 2022-07-25 16:07:42 +02:00
Fran Zekan
927c4afcc8 Merge branch 'main' into feature/add-revalidate-page-to-mutations 2022-07-25 11:34:35 +02:00
Fran Zekan
06241b24e3 fix lock 2022-07-25 00:18:06 +02:00
Fran Zekan
9fe1cb5c86 Better start commands for demo apps 2022-07-25 00:17:43 +02:00
Fran Zekan
c5a37ac12d Add example for GSP revalidation 2022-07-25 00:17:08 +02:00
Fran Zekan
162dc98508 Add revalidatePage utils 2022-07-25 00:16:47 +02:00
Fran Zekan
29e7d641ca Fix TS error 2022-07-25 00:15:51 +02:00
19 changed files with 3653 additions and 3775 deletions

View File

@@ -10,4 +10,4 @@
Bump react, react-dom, @types/react and next versions
This fixes a console warning: `Warning: Received `true` for a non-boolean attribute `global`.` when using `styled-jsx`. Versions bump also fixes React Hydration error that happens on and off when using `redirectAuthenticatedTo`.
This fixes a console warning: `Warning: Received `true`for a non-boolean attribute`global`.` when using `styled-jsx`. Versions bump also fixes React Hydration error that happens on and off when using `redirectAuthenticatedTo`.

View File

@@ -1,5 +1,5 @@
---
"@blitzjs/codemod": patch
---
Add DocumentProps & DocumentContext to the codemod import map
Add DocumentProps & DocumentContext to the codemod import map

View File

@@ -3,4 +3,4 @@
"@blitzjs/generator": patch
---
Fix `cannot find module db error` in JavaScript template. Replace requiring the config using `esbuild` with parsing using `jscodeshift` to get the `cliConfig` values. Added logic to find the `blitz-server` file in `src` directory
Fix `cannot find module db error` in JavaScript template. Replace requiring the config using `esbuild` with parsing using `jscodeshift` to get the `cliConfig` values. Added logic to find the `blitz-server` file in `src` directory

View File

@@ -2,4 +2,4 @@
"blitz": patch
---
Fix Custom Server TS error - add `es6` target config to esbuild
Fix Custom Server TS error - add `es6` target config to esbuild

View File

@@ -5,4 +5,5 @@
"blitz": patch
"@blitzjs/generator": patch
---
Fixes the supports-color warning for pnpm

View File

@@ -5,7 +5,7 @@ To make sure your PR is handled as smoothly as possible please:
- Choose & follow the right checklist for the change that you're making:
Please make sure to add a changeset. Run `pnpm changeset` in the root directory to do so.
Then select updated Blitz packages when prompted, and add a short message describing the changes.
Then select updated Blitz packages when prompted, and add a short message describing the changes.
The message should be user-facing — explain **what** was changed, not **how**.
Ignore if there are no user-facing changes.
-->

View File

@@ -7,8 +7,8 @@ on:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
jobs:
@@ -143,7 +143,7 @@ jobs:
- name: Install playwright
run: |
pnpx playwright@1.28.0 install --with-deps
pnpx playwright@1.28.0 install --with-deps
shell: bash
- name: Build

View File

@@ -27,7 +27,7 @@ jobs:
uses: eficode/resolve-pr-refs@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v3
with:
ref: ${{ steps.refs.outputs.head_ref }}
@@ -39,18 +39,18 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
cache: 'pnpm'
registry-url: "https://registry.npmjs.org"
cache: "pnpm"
- name: Short SHA
id: vars
run: echo "sha_short=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_OUTPUT
- name: Extract the snapshot name from comment body
id: getSnapshotName
uses: actions/github-script@v6
with:
script: |
script: |
const splitComment = context.payload.comment.body.split(' ');
if(splitComment.length !== 2) {
return "${{ steps.vars.outputs.sha_short }}";
@@ -60,7 +60,7 @@ jobs:
- name: Install dependencies
run: pnpm install
env:
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- name: Build Packages
@@ -99,4 +99,3 @@ jobs:
repo: context.repo.repo,
body: '```\n' + process.env.MESSAGE + '\n```',
})

View File

@@ -1,2 +1 @@
# toolkit-app-passportjs

View File

@@ -3,8 +3,9 @@
"version": "1.0.1-alpha.16",
"scripts": {
"start:dev": "pnpm run prisma:start && blitz dev",
"buildapp": "pnpm blitz codegen && pnpm prisma generate && next build",
"start:full": "pnpm buildapp && pnpm start",
"start": "next start",
"buildapp": "pnpm blitz codegen && pnpm prisma generate && next build",
"lint": "next lint",
"prisma:start": "prisma generate && prisma migrate deploy",
"prisma:studio": "prisma studio",

View File

@@ -3,9 +3,10 @@
"version": "0.0.0",
"private": true,
"scripts": {
"start:dev": "pnpm run prisma:start && next dev",
"buildapp": "pnpm blitz codegen && pnpm prisma generate && next build",
"start": "next start",
"start:dev": "pnpm run prisma:start && next dev",
"start:full": "pnpm buildapp && pnpm start",
"buildapp": "pnpm blitz codegen && pnpm prisma generate && next build",
"lint": "next lint",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf .next",
"prisma:start": "prisma generate && prisma migrate deploy",

View File

@@ -0,0 +1,10 @@
import {resolver} from "@blitzjs/rpc"
import {Routes} from "@blitzjs/next"
const revalidateFn = resolver.pipe(async (_, ctx) => {
await ctx.revalidatePage(Routes.PageWithGsp())
return true
})
export default revalidateFn

View File

@@ -1,4 +1,7 @@
import {gSP} from "src/blitz-server"
import React from "react"
import {gSP} from "app/blitz-server"
import {useMutation} from "@blitzjs/rpc"
import revalidateFn from "app/mutations/revalidate"
export const getStaticProps = gSP<{data: {test: string}}>(async ({ctx}) => {
return {
@@ -12,7 +15,18 @@ export const getStaticProps = gSP<{data: {test: string}}>(async ({ctx}) => {
})
function PageWithGsp({data}) {
return <div>{JSON.stringify(data, null, 2)}</div>
const [prefetch, {isLoading}] = useMutation(revalidateFn)
return (
<div>
<button onClick={() => prefetch()} disabled={isLoading}>
Revalidate GSP data
</button>
<br />
{JSON.stringify(data, null, 2)}
</div>
)
}
export default PageWithGsp

View File

@@ -6,4 +6,3 @@ export default defineConfig({
hookTimeout: 100000,
},
})

View File

@@ -18,7 +18,13 @@ import {
BlitzLogger,
initializeLogger,
} from "blitz"
import {handleRequestWithMiddleware, startWatcher, stopWatcher} from "blitz"
import {
handleRequestWithMiddleware,
startWatcher,
stopWatcher,
RouteUrlObject,
isRouteUrlObject,
} from "blitz"
import {
dehydrate,
getInfiniteQueryKey,
@@ -29,11 +35,12 @@ import {
} from "@blitzjs/rpc"
import {DefaultOptions, QueryClient} from "@tanstack/react-query"
import {IncomingMessage, ServerResponse} from "http"
import {withSuperJsonProps} from "./superjson"
import {ParsedUrlQuery} from "querystring"
import {PreviewData} from "next/types"
import {resolveHref} from "next/dist/shared/lib/router/router"
import {RouteUrlObject, isRouteUrlObject} from "blitz"
import {withSuperJsonProps} from "./superjson"
import {revalidateMiddleware} from "./next-revalidate"
export * from "./index-browser"
@@ -94,7 +101,7 @@ export type BlitzGSPHandler<
> = ({
ctx,
...args
}: Parameters<GetStaticProps<TProps, Query, PD>>[0] & {ctx: Ctx}) =>
}: Parameters<GetStaticProps<TProps, Query, PD>>[0] & {ctx: Omit<Ctx, "revalidatePage">}) =>
| Promise<BlitzGSPResult<TProps>>
| BlitzGSPResult<TProps>
@@ -133,7 +140,7 @@ const prefetchQueryFactory = (
export const setupBlitzServer = ({plugins, onError, logger}: SetupBlitzOptions) => {
initializeLogger(logger ?? BlitzLogger())
const middlewares = plugins.flatMap((p) => p.requestMiddlewares)
const middlewares = [...plugins.flatMap((p) => p.requestMiddlewares), revalidateMiddleware]
const contextMiddleware = plugins.flatMap((p) => p.contextMiddleware).filter(Boolean)
const gSSP =
@@ -185,6 +192,9 @@ export const setupBlitzServer = ({plugins, onError, logger}: SetupBlitzOptions)
ctx.prefetchQuery = prefetchQuery
ctx.prefetchInfiniteQuery = (...args) => prefetchQuery(...args, true)
ctx.revalidatePage = () => {
throw new Error("revalidatePage is not supported in GSP")
}
try {
const result = await handler({...context, ctx: ctx})
@@ -309,5 +319,7 @@ declare module "blitz" {
export interface Ctx {
prefetchQuery: PrefetchQueryFn
prefetchInfiniteQuery: PrefetchQueryFn
revalidatePage: NextApiResponse["revalidate"]
}
}

View File

@@ -0,0 +1,42 @@
// copied from https://github.com/blitz-js/blitz/blob/a8046e604ace8bf544c544972328232820cd3d26/packages/blitz-auth/src/server/auth-sessions.ts#L127
import {IncomingMessage, ServerResponse} from "http"
import {UrlObject} from "url"
import {Ctx, RequestMiddleware} from "blitz"
import {NextApiResponse} from "next"
import {NextRouter, resolveHref} from "next/dist/shared/lib/router/router"
export function ensureMiddlewareResponse(
res: ServerResponse & {[key: string]: any},
): asserts res is ServerResponse & {blitzCtx: Ctx} {
if (!("blitzCtx" in res)) {
res.blitzCtx = {} as Ctx
}
}
export function ensureResponseHasRevalidate(
res: ServerResponse & {[key: string]: any},
): res is ServerResponse & {revalidate: NextApiResponse["revalidate"]} {
return !("revalidate" in res)
}
export const revalidateMiddleware: RequestMiddleware<
IncomingMessage,
ServerResponse,
void | Promise<void>
> = (req, res, next) => {
ensureMiddlewareResponse(res)
if (!ensureResponseHasRevalidate(res)) {
return next()
}
if (!("revalidatePage" in res.blitzCtx)) {
res.blitzCtx.revalidatePage = (
url: UrlObject | string,
opts?: Parameters<NextApiResponse["revalidate"]>[1],
) => res.revalidate(resolveHref({} as NextRouter, url, false), opts)
}
return next()
}

View File

@@ -16,7 +16,7 @@ export const PAGES_DIR_ALIAS = "private-next-pages"
/* Fetch next.js config */
export const VALID_LOADERS = ["default", "imgix", "cloudinary", "akamai", "custom"] as const
export type LoaderValue = typeof VALID_LOADERS[number]
export type LoaderValue = (typeof VALID_LOADERS)[number]
export type ImageConfig = {
deviceSizes: number[]
imageSizes: number[]

View File

@@ -1,5 +1,5 @@
import {IncomingMessage, ServerResponse} from "http"
import {compose, Ctx, RequestMiddleware, MiddlewareNext, MiddlewareResponse} from "./index-server"
import {compose, RequestMiddleware, MiddlewareNext, MiddlewareResponse} from "./index-server"
export async function handleRequestWithMiddleware<
Req extends IncomingMessage = IncomingMessage,
@@ -17,9 +17,6 @@ export async function handleRequestWithMiddleware<
stackPrintOnError?: boolean
} = {},
) {
if (!(res as unknown as MiddlewareResponse).blitzCtx) {
;(res as unknown as MiddlewareResponse).blitzCtx = {} as Ctx
}
if (!(res as any)._blitz) {
;(res as any)._blitz = {}
}

7287
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff