Skip to content

Commit

Permalink
Merge branch 'canary' into example/image-component
Browse files Browse the repository at this point in the history
  • Loading branch information
HaNdTriX committed Sep 2, 2022
2 parents 6c6bdd8 + abcf991 commit 907fe5a
Show file tree
Hide file tree
Showing 23 changed files with 271 additions and 43 deletions.
16 changes: 8 additions & 8 deletions examples/convex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_mediu
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example:

```bash
npx create-next-app --example with-convex with-convex-app
npx create-next-app --example convex convex-app
# or
yarn create next-app --example with-convex with-convex-app
yarn create next-app --example convex convex-app
# or
pnpm create next-app --example with-convex with-convex-app
pnpm create next-app --example convex convex-app
```

Log in to Convex,
Expand All @@ -32,16 +32,16 @@ initialize a new Convex project,
npx convex init
```

and push the Convex functions for this project.
and then run the following two commands in two different terminals:

```bash
npx convex push
npx convex dev
```

Now you can run your code locally with a Convex backend with

```bash
npm run dev
```

Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
Once everything is working, commit your code and deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).

Use `npx convex deploy && npm run build` as the build command and set the `CONVEX_DEPLOY_KEY` environmental variable in Vercel ([Documentation](https://docs.convex.dev/getting-started/deployment/hosting/vercel)).
2 changes: 1 addition & 1 deletion examples/convex/convex/_generated/dataModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@0.1.8.
* Generated by convex@0.1.9.
* To regenerate, run `npx convex codegen`.
* @module
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/convex/convex/_generated/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@0.1.8.
* Generated by convex@0.1.9.
* To regenerate, run `npx convex codegen`.
* @module
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/convex/convex/_generated/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@0.1.8.
* Generated by convex@0.1.9.
* To regenerate, run `npx convex codegen`.
* @module
*/
Expand Down
4 changes: 2 additions & 2 deletions examples/convex/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import '../styles/globals.css'
import type { AppProps } from 'next/app'

import { ConvexProvider, ConvexReactClient } from 'convex/react'
import convexConfig from '../convex.json'
const convex = new ConvexReactClient(convexConfig.origin)
import clientConfig from '../convex/_generated/clientConfig'
const convex = new ConvexReactClient(clientConfig)

function MyApp({ Component, pageProps }: AppProps) {
return (
Expand Down
37 changes: 37 additions & 0 deletions examples/with-axiom/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel

# typescript
*.tsbuildinfo
25 changes: 25 additions & 0 deletions examples/with-axiom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Example app with Axiom

This example shows how to use a [Next.js](https://nextjs.org/) project along with [Axiom](https://axiom.co) via the [next-axiom](https://github.com/axiomhq/next-axiom) package. A custom `withAxiom` wrapper is used to wrap the next config object, middleware and API functions. The `log` object could be used from frontend, middleware and API functions.

## Deploy your own

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) or preview live with [StackBlitz](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-axiom)

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-axiom&project-name=with-axiom&repository-name=with-axiom)

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example::

```bash
npx create-next-app --example with-axiom with-axiom-app
# or
yarn create next-app --example with-axiom with-axiom-app
# or
pnpm create next-app --example with-axiom with-axiom-app
```

Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)) and watch data coming into your Axiom dataset.
9 changes: 9 additions & 0 deletions examples/with-axiom/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { NextResponse } from 'next/server'
import { log, withAxiom } from 'next-axiom'

async function middleware() {
log.info('Hello from middleware', { bar: 'baz' })
return NextResponse.next()
}

export default withAxiom(middleware)
5 changes: 5 additions & 0 deletions examples/with-axiom/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
8 changes: 8 additions & 0 deletions examples/with-axiom/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { withAxiom } = require('next-axiom')

/** @type {import('next').NextConfig} */
const nextConfig = withAxiom({
reactStrictMode: true,
})

module.exports = nextConfig
21 changes: 21 additions & 0 deletions examples/with-axiom/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"next-axiom": "^0.10.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"swr": "^1.3.0"
},
"devDependencies": {
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.1",
"@types/node": "^16.11.26",
"typescript": "^4.7.4"
}
}
11 changes: 11 additions & 0 deletions examples/with-axiom/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { log } from 'next-axiom'
import { AppProps } from 'next/app'
export { reportWebVitals } from 'next-axiom'

log.info('Hello from frontend', { foo: 'bar' })

const MyApp = ({ Component, pageProps }: AppProps) => {
return <Component {...pageProps} />
}

export default MyApp
10 changes: 10 additions & 0 deletions examples/with-axiom/pages/api/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
import { log, withAxiom } from 'next-axiom'

async function handler(req: NextApiRequest, res: NextApiResponse) {
log.info('Hello from function', { url: req.url })
res.status(200).json({ name: 'John Doe' })
}

export default withAxiom(handler)
31 changes: 31 additions & 0 deletions examples/with-axiom/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { GetStaticPropsContext } from 'next'
import { log } from 'next-axiom'
import useSWR from 'swr'

export const getStaticProps = async (ctx: GetStaticPropsContext) => {
log.info('Hello from SSR', { ctx })
return {
props: {},
}
}

const fetcher = async (...args: any[]) => {
log.info('Hello from SWR', { args })
const res = await fetch.apply(null, [...args])
return await res.json()
}

const Home = () => {
const { data, error } = useSWR('/api/hello', fetcher)

if (error) return <div>Failed to load</div>
if (!data) return <div>Loading...</div>

return (
<div>
<h1>{data.name}</h1>
</div>
)
}

export default Home
19 changes: 19 additions & 0 deletions examples/with-axiom/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
8 changes: 7 additions & 1 deletion packages/next/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,13 @@ export async function copyTracedFiles(
const symlink = await fs.readlink(tracedFilePath).catch(() => null)

if (symlink) {
await fs.symlink(symlink, fileOutputPath)
try {
await fs.symlink(symlink, fileOutputPath)
} catch (e: any) {
if (e.code !== 'EEXIST') {
throw e
}
}
} else {
await fs.copyFile(tracedFilePath, fileOutputPath)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/next/compiled/@vercel/nft/index.js

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions packages/next/lib/eslint/hasEslintConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ export async function hasEslintConfiguration(
}
return { ...configObject, exists: true }
} else if (packageJsonConfig?.eslintConfig) {
if (Object.entries(packageJsonConfig?.eslintConfig).length === 0) {
return {
...configObject,
emptyPkgJsonConfig: true,
}
if (Object.keys(packageJsonConfig?.eslintConfig).length) {
return { ...configObject, exists: true }
}
return { ...configObject, emptyPkgJsonConfig: true }
}
return configObject
}
4 changes: 2 additions & 2 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@swc/helpers": "0.4.3",
"caniuse-lite": "^1.0.30001332",
"postcss": "8.4.14",
"styled-jsx": "5.0.4",
"styled-jsx": "5.0.5",
"use-sync-external-store": "1.2.0"
},
"peerDependencies": {
Expand Down Expand Up @@ -165,7 +165,7 @@
"@types/webpack-sources1": "npm:@types/webpack-sources@0.1.5",
"@types/ws": "8.2.0",
"@vercel/ncc": "0.34.0",
"@vercel/nft": "0.22.0",
"@vercel/nft": "0.22.1",
"acorn": "8.5.0",
"ajv": "8.11.0",
"amphtml-validator": "1.0.35",
Expand Down
18 changes: 10 additions & 8 deletions packages/next/shared/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ function withMiddlewareEffects<T extends FetchDataOutput>(
getMiddlewareData(data.dataHref, data.response, options).then(
(effect) => ({
dataHref: data.dataHref,
cacheKey: data.cacheKey,
json: data.json,
response: data.response,
text: data.text,
Expand Down Expand Up @@ -639,6 +640,7 @@ interface FetchDataOutput {
json: Record<string, any> | null
response: Response
text: string
cacheKey: string
}

interface FetchNextDataParams {
Expand Down Expand Up @@ -680,7 +682,7 @@ function fetchNextData({
})
.then((response) => {
if (response.ok && params?.method === 'HEAD') {
return { dataHref, response, text: '', json: {} }
return { dataHref, response, text: '', json: {}, cacheKey }
}

return response.text().then((text) => {
Expand All @@ -695,7 +697,7 @@ function fetchNextData({
hasMiddleware &&
[301, 302, 307, 308].includes(response.status)
) {
return { dataHref, response, text, json: {} }
return { dataHref, response, text, json: {}, cacheKey }
}

if (!hasMiddleware && response.status === 404) {
Expand All @@ -705,6 +707,7 @@ function fetchNextData({
json: { notFound: SSG_DATA_NOT_FOUND },
response,
text,
cacheKey,
}
}
}
Expand All @@ -728,6 +731,7 @@ function fetchNextData({
json: parseJSON ? tryToParseAsJSON(text) : null,
response,
text,
cacheKey,
}
})
})
Expand Down Expand Up @@ -2014,9 +2018,9 @@ export default class Router implements BaseRouter {
const shouldFetchData =
routeInfo.__N_SSG || routeInfo.__N_SSP || routeInfo.__N_RSC

const { props } = await this._getData(async () => {
const { props, cacheKey } = await this._getData(async () => {
if (shouldFetchData && !useStreamedFlightData) {
const { json } = data?.json
const { json, cacheKey: _cacheKey } = data?.json
? data
: await fetchNextData({
dataHref: this.pageLoader.getDataHref({
Expand All @@ -2033,12 +2037,14 @@ export default class Router implements BaseRouter {
})

return {
cacheKey: _cacheKey,
props: json || {},
}
}

return {
headers: {},
cacheKey: '',
props: await this.getInitialProps(
routeInfo.Component,
// we provide AppTree later so this needs to be `any`
Expand All @@ -2058,10 +2064,6 @@ export default class Router implements BaseRouter {
// middleware can skip cache per request with
// x-middleware-cache: no-cache as well
if (routeInfo.__N_SSP && fetchNextDataParams.dataHref) {
const cacheKey = new URL(
fetchNextDataParams.dataHref,
window.location.href
).href
delete this.sdc[cacheKey]
}

Expand Down

0 comments on commit 907fe5a

Please sign in to comment.