Skip to content

Commit

Permalink
Merge branch 'canary' into canary
Browse files Browse the repository at this point in the history
  • Loading branch information
eungyeole committed Feb 24, 2022
2 parents 9774304 + cc5345b commit 1ee48e2
Show file tree
Hide file tree
Showing 33 changed files with 179 additions and 69 deletions.
2 changes: 1 addition & 1 deletion docs/advanced-features/custom-document.md
Expand Up @@ -41,7 +41,7 @@ Or add a `className` to the `body` tag:
## Caveats

- The `<Head />` component used in `_document` is not the same as [`next/head`](/docs/api-reference/next/head.md). The `<Head />` component used here should only be used for any `<head>` code that is common for all pages. For all other cases, such as `<title>` tags, we recommend using [`next/head`](/docs/api-reference/next/head.md) in your pages or components.
- React components outside of `<Main />` will not be initialized by the browser. Do _not_ add application logic here or custom CSS (like `styled-jsx`). If you need shared components in all your pages (like a menu or a toolbar), read [Layouts](/docs/basic-features/layouts.md) intead.
- React components outside of `<Main />` will not be initialized by the browser. Do _not_ add application logic here or custom CSS (like `styled-jsx`). If you need shared components in all your pages (like a menu or a toolbar), read [Layouts](/docs/basic-features/layouts.md) instead.
- `Document` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching/overview.md) like [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) or [`getServerSideProps`](/docs/basic-features/data-fetching/get-server-side-props.md).

## Customizing `renderPage`
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions examples/with-redis/next-env.d.ts
@@ -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.
7 changes: 6 additions & 1 deletion examples/with-redis/package.json
Expand Up @@ -19,6 +19,11 @@
"uuid": "^8.3.2"
},
"devDependencies": {
"@tailwindcss/jit": "0.1.1"
"@tailwindcss/jit": "0.1.1",
"@types/ioredis": "4.28.8",
"@types/node": "^16.11.25",
"@types/react": "^17.0.2",
"@types/uuid": "8.3.4",
"typescript": "^4.5.5"
}
}
@@ -1,7 +1,9 @@
import type { AppProps } from 'next/app'

import '../styles/globals.css'
import { Toaster } from 'react-hot-toast'

function MyApp({ Component, pageProps }) {
function MyApp({ Component, pageProps }: AppProps) {
return (
<>
<Component {...pageProps} />
Expand Down
@@ -1,8 +1,12 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import { v4 as uuidv4 } from 'uuid'

import redis from '../../lib/redis'

export default async function create(req, res) {
export default async function create(
req: NextApiRequest,
res: NextApiResponse
) {
const { title } = req.body

if (!title) {
Expand Down
@@ -1,6 +1,11 @@
import type { NextApiRequest, NextApiResponse } from 'next'

import redis from '../../lib/redis'

export default async function getAllFeatures(req, res) {
export default async function getAllFeatures(
req: NextApiRequest,
res: NextApiResponse
) {
const features = (await redis.hvals('features'))
.map((entry) => JSON.parse(entry))
.sort((a, b) => b.score - a.score)
Expand Down
@@ -1,6 +1,11 @@
import type { NextApiRequest, NextApiResponse } from 'next'

import redis from '../../lib/redis'

export default async function subscribe(req, res) {
export default async function subscribe(
req: NextApiRequest,
res: NextApiResponse
) {
const { email } = req.body

if (email && validateEmail(email)) {
Expand All @@ -15,7 +20,7 @@ export default async function subscribe(req, res) {
}
}

function validateEmail(email) {
function validateEmail(email: string) {
const re =
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return re.test(String(email).toLowerCase())
Expand Down
@@ -1,6 +1,11 @@
import type { NextApiRequest, NextApiResponse } from 'next'

import redis from '../../lib/redis'

export default async function upvote(req, res) {
export default async function upvote(
req: NextApiRequest,
res: NextApiResponse
) {
const { title, id } = req.body
const ip =
req.headers['x-forwarded-for'] || req.headers['Remote_Addr'] || 'NA'
Expand Down
@@ -1,13 +1,22 @@
import { useState, useRef } from 'react'
import type { NextApiRequest } from 'next'
import type { MouseEvent } from 'react'
import Head from 'next/head'
import clsx from 'clsx'
import useSWR, { mutate } from 'swr'
import toast from 'react-hot-toast'
import redis from '../lib/redis'

const fetcher = (url) => fetch(url).then((res) => res.json())
type Feature = {
id: string
title: string
score: number
ip: string
}

const fetcher = (url: string) => fetch(url).then((res) => res.json())

function LoadingSpinner({ invert }) {
function LoadingSpinner({ invert }: { invert?: boolean }) {
return (
<svg
className={clsx(
Expand Down Expand Up @@ -35,8 +44,20 @@ function LoadingSpinner({ invert }) {
)
}

function Item({ isFirst, isLast, isReleased, hasVoted, feature }) {
const upvote = async (e) => {
function Item({
isFirst,
isLast,
isReleased,
hasVoted,
feature,
}: {
isFirst: boolean
isLast: boolean
isReleased: boolean
hasVoted: boolean
feature: Feature
}) {
const upvote = async (e: MouseEvent<HTMLButtonElement>) => {
e.preventDefault()

const res = await fetch('/api/vote', {
Expand Down Expand Up @@ -85,11 +106,17 @@ function Item({ isFirst, isLast, isReleased, hasVoted, feature }) {
)
}

export default function Roadmap({ features, ip }) {
export default function Roadmap({
features,
ip,
}: {
features: Feature[]
ip: string
}) {
const [isCreateLoading, setCreateLoading] = useState(false)
const [isEmailLoading, setEmailLoading] = useState(false)
const featureInputRef = useRef(null)
const subscribeInputRef = useRef(null)
const featureInputRef = useRef<HTMLInputElement>(null)
const subscribeInputRef = useRef<HTMLInputElement>(null)

const { data, error } = useSWR('/api/features', fetcher, {
initialData: { features },
Expand All @@ -99,13 +126,13 @@ export default function Roadmap({ features, ip }) {
toast.error(error)
}

const addFeature = async (e) => {
const addFeature = async (e: MouseEvent<HTMLFormElement>) => {
e.preventDefault()
setCreateLoading(true)

const res = await fetch('/api/create', {
body: JSON.stringify({
title: featureInputRef.current.value,
title: featureInputRef?.current?.value ?? '',
}),
headers: {
'Content-Type': 'application/json',
Expand All @@ -122,16 +149,18 @@ export default function Roadmap({ features, ip }) {
}

mutate('/api/features')
featureInputRef.current.value = ''
if (featureInputRef.current) {
featureInputRef.current.value = ''
}
}

const subscribe = async (e) => {
const subscribe = async (e: MouseEvent<HTMLFormElement>) => {
e.preventDefault()
setEmailLoading(true)

const res = await fetch('/api/subscribe', {
body: JSON.stringify({
email: subscribeInputRef.current.value,
email: subscribeInputRef?.current?.value ?? '',
}),
headers: {
'Content-Type': 'application/json',
Expand All @@ -147,7 +176,10 @@ export default function Roadmap({ features, ip }) {
}

toast.success('You are now subscribed to feature updates!')
subscribeInputRef.current.value = ''

if (subscribeInputRef.current) {
subscribeInputRef.current.value = ''
}
}

return (
Expand Down Expand Up @@ -189,7 +221,7 @@ export default function Roadmap({ features, ip }) {
</form>
</div>
<div className="w-full">
{data.features.map((feature, index) => (
{data.features.map((feature: Feature, index: number) => (
<Item
key={index}
isFirst={index === 0}
Expand Down Expand Up @@ -254,7 +286,7 @@ export default function Roadmap({ features, ip }) {
)
}

export async function getServerSideProps({ req }) {
export async function getServerSideProps({ req }: { req: NextApiRequest }) {
const ip =
req.headers['x-forwarded-for'] || req.headers['Remote_Addr'] || 'NA'
const features = (await redis.hvals('features'))
Expand Down
21 changes: 21 additions & 0 deletions examples/with-redis/tsconfig.json
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"baseUrl": ".",
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.1.1-canary.1"
"version": "12.1.1-canary.2"
}
1 change: 0 additions & 1 deletion packages/create-next-app/create-app.ts
Expand Up @@ -127,7 +127,6 @@ export async function createApp({
console.log(`Creating a new Next.js app in ${chalk.green(root)}.`)
console.log()

await makeDir(root)
process.chdir(root)

if (example) {
Expand Down
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "12.1.1-canary.1",
"version": "12.1.1-canary.2",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "12.1.1-canary.1",
"version": "12.1.1-canary.2",
"description": "ESLint configuration used by NextJS.",
"main": "index.js",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
"directory": "packages/eslint-config-next"
},
"dependencies": {
"@next/eslint-plugin-next": "12.1.1-canary.1",
"@next/eslint-plugin-next": "12.1.1-canary.2",
"@rushstack/eslint-patch": "^1.0.8",
"@typescript-eslint/parser": "^5.0.0",
"eslint-import-resolver-node": "^0.3.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "12.1.1-canary.1",
"version": "12.1.1-canary.2",
"description": "ESLint plugin for NextJS.",
"main": "lib/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "12.1.1-canary.1",
"version": "12.1.1-canary.2",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "12.1.1-canary.1",
"version": "12.1.1-canary.2",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "12.1.1-canary.1",
"version": "12.1.1-canary.2",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "12.1.1-canary.1",
"version": "12.1.1-canary.2",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "12.1.1-canary.1",
"version": "12.1.1-canary.2",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "12.1.1-canary.1",
"version": "12.1.1-canary.2",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "12.1.1-canary.1",
"version": "12.1.1-canary.2",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "12.1.1-canary.1",
"version": "12.1.1-canary.2",
"private": true,
"scripts": {
"build-native": "napi build --platform --cargo-name next_swc_napi native",
Expand Down
10 changes: 5 additions & 5 deletions packages/next/build/webpack-config.ts
Expand Up @@ -1848,11 +1848,11 @@ export default async function getBaseWebpackConfig(
}

const fileNames = [
'/tmp/test.css',
'/tmp/test.scss',
'/tmp/test.sass',
'/tmp/test.less',
'/tmp/test.styl',
'/tmp/NEXTJS_CSS_DETECTION_FILE.css',
'/tmp/NEXTJS_CSS_DETECTION_FILE.scss',
'/tmp/NEXTJS_CSS_DETECTION_FILE.sass',
'/tmp/NEXTJS_CSS_DETECTION_FILE.less',
'/tmp/NEXTJS_CSS_DETECTION_FILE.styl',
]

if (rule instanceof RegExp && fileNames.some((input) => rule.test(input))) {
Expand Down

0 comments on commit 1ee48e2

Please sign in to comment.