Skip to content

Commit

Permalink
fix typescript errors in next-core (#47415)
Browse files Browse the repository at this point in the history
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
  • Loading branch information
ForsakenHarmony committed Mar 28, 2023
1 parent 69610fc commit b95d678
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ReactDOMClient from "react-dom/client";
import React, { use } from "react";
import type { ReactElement } from "react";
// @ts-expect-error
import { version } from "next/package.json";
import { createFromReadableStream } from "next/dist/compiled/react-server-dom-webpack/client";
import { callServer } from 'next/dist/client/app-call-server';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ import * as serverHooks from "next/dist/client/components/hooks-server-context.j
export { serverHooks };
export { renderToReadableStream } from "next/dist/compiled/react-server-dom-webpack/server.edge";

// @ts-expect-error PAGE is provided by rust
import * as module from "PAGE";
export { module };
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { requestAsyncStorage } from "next/dist/client/components/request-async-s

enhanceGlobals();

// @ts-expect-error ENTRY is set from rust code
import * as handlers from "ENTRY";
const mod = {
handlers,
Expand All @@ -25,6 +24,7 @@ const mod = {
const handler = getHandle({
mod,
page: `/${PAGE}`,
nextConfigOutput: undefined
});

// @ts-ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
startHandler(async ({ request, response, query, params, path }) => {
const edgeInfo = {
name: "edge",
paths: chunkGroup.map((chunk: string) =>
paths: chunkGroup.map((chunk) =>
join(process.cwd(), ".next/server/app", chunk)
),
wasm: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { createProxy } from "next/dist/build/webpack/loaders/next-flight-loader/module-proxy";

("TURBOPACK { chunking-type: isolatedParallel }");
// @ts-expect-error CLIENT_MODULE is provided by rust
import { __turbopack_module_id__ as id } from "CLIENT_MODULE";

// @ts-expect-error CLIENT_CHUNKS is provided by rust
import client_id, { chunks, chunkListPath } from "CLIENT_CHUNKS";

export default createProxy(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createProxy } from "next/dist/build/webpack/loaders/next-flight-loader/module-proxy";

// @ts-expect-error CLIENT_CHUNKS is provided by rust
import client_id, { chunks, chunkListPath } from "CLIENT_CHUNKS";

export default createProxy(JSON.stringify([client_id, chunks, chunkListPath]));
7 changes: 1 addition & 6 deletions packages/next-swc/crates/next-core/js/src/entry/error.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
// TODO(alexkirsz) export * would be preferrable here once supported.
export {
default,
getStaticProps,
__N_SSG,
__N_SSP,
} from "@vercel/turbopack-next/internal/_error";
export { default } from "@vercel/turbopack-next/internal/_error";
14 changes: 0 additions & 14 deletions packages/next-swc/crates/next-core/js/src/entry/next-hydrate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,15 @@ import { formatWithValidation } from "next/dist/shared/lib/router/utils/format-u
import { initializeHMR } from "@vercel/turbopack-next/dev/client";
import {
subscribeToUpdate,
subscribeToCssChunkUpdates,
} from "@vercel/turbopack-next/dev/hmr-client";

import * as _app from "@vercel/turbopack-next/pages/_app";
// @ts-expect-error PAGE is provided by rust
import * as page from "PAGE";

async function loadPageChunk(assetPrefix: string, chunkPath: string) {
const fullPath = assetPrefix + chunkPath;

await __turbopack_load__(fullPath);

// TODO: the turbopack chunk loader should do this somehow
if (chunkPath.endsWith(".css")) {
const link = document.querySelector<HTMLLinkElement>(
`link[href=${JSON.stringify(fullPath)}]`
);
if (!link) {
throw new Error("stylesheet should be loaded, but is not");
}

subscribeToCssChunkUpdates(assetPrefix, link);
}
}

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/next-core/js/src/entry/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function getResolveRoute(
);

return await makeResolver(dir, nextConfig, {
files: middlewareChunkGroup.filter((f) => /\.[mc]?js$/.test(f)),
files: middlewareChunkGroup.filter((f: string) => /\.[mc]?js$/.test(f)),
matcher: middlewareConfig.matcher,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import startHandler from "@vercel/turbopack-next/internal/api-server-handler";

import "next/dist/server/node-polyfill-fetch.js";

// @ts-expect-error INNER is provided by rust
import * as allExports from "INNER";
import { apiResolver } from "next/dist/server/api-utils/node";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import startHandler from "@vercel/turbopack-next/internal/page-server-handler";
// eslint-disable-next-line
import Document from "next/document";
import App from "next/app";
// @ts-expect-error INNER is provided by rust

import * as otherExports from "INNER";

startHandler({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { join } from "path";

import "next/dist/server/node-polyfill-fetch.js";

// @ts-expect-error INNER_EDGE_CHUNK_GROUP is provided by rust
import chunkGroup from "INNER_EDGE_CHUNK_GROUP";

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import startHandler from "@vercel/turbopack-next/internal/page-server-handler";
import App from "@vercel/turbopack-next/pages/_app";
import Document from "@vercel/turbopack-next/pages/_document";

// @ts-expect-error INNER is provided by rust
import Component, * as otherExports from "INNER";

// @ts-expect-error INNER_CLIENT_CHUNK_GROUP is provided by rust
import chunkGroup from "INNER_CLIENT_CHUNK_GROUP";

startHandler({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export default function startHandler({
optimizeFonts: false,
optimizeCss: false,
nextScriptWorkers: false,
supportsDynamicHTML: true,
images: {
deviceSizes: [],
imageSizes: [],
Expand All @@ -188,6 +189,7 @@ export default function startHandler({
formats: [],
dangerouslyAllowSVG: false,
contentSecurityPolicy: "",
contentDispositionType: 'inline',
remotePatterns: [],
unoptimized: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "./shims";

// Necessary for Next.js to accept and handle the `webpackHMR` option properly
// in next-hydrate.js.
// @ts-expect-error next.js sets this as readonly in their `global.d.ts`
process.env.NODE_ENV = "development";

// This is a fix for web-vitals.js not being linked properly.
Expand Down
5 changes: 5 additions & 0 deletions packages/next-swc/crates/next-core/js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@
"@vercel/turbopack-next/*": ["src/*"],
"@vercel/turbopack-next/pages/_app": ["node_modules/next/app"],
"@vercel/turbopack-next/pages/_document": ["node_modules/next/document"],
"@vercel/turbopack-next/internal/_error": ["node_modules/next/error"],
"next/*": ["node_modules/next/*"]
},
"resolveJsonModule": true,
"types": [
"react/next"
],

// emit
"noEmit": true,
Expand Down
68 changes: 68 additions & 0 deletions packages/next-swc/crates/next-core/js/types/rust.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// modules provided by rust

declare module 'PAGE' {
import {
NextPage,
GetStaticPaths,
GetServerSideProps,
GetStaticProps,
} from 'next'

const Component: NextPage
export default Component

export const getStaticProps: GetStaticProps | undefined
export const getStaticPaths: GetStaticPaths | undefined
export const getServerSideProps: GetServerSideProps | undefined
}

declare module 'INNER' {
export * from 'PAGE'
}

declare module 'CHUNK_GROUP' {
const chunkGroup: import('types/next').ChunkGroup
export default chunkGroup
}

declare module 'MIDDLEWARE_CHUNK_GROUP' {
export { default } from 'CHUNK_GROUP'
}

declare module 'INNER_CLIENT_CHUNK_GROUP' {
export { default } from 'CHUNK_GROUP'
}

declare module 'INNER_EDGE_CHUNK_GROUP' {
export { default } from 'CHUNK_GROUP'
}

declare module 'ROUTE_CHUNK_GROUP' {
export { default } from 'CHUNK_GROUP'
}

declare module 'MIDDLEWARE_CONFIG' {
const matcher: string[]
export default {
matcher,
}
}

declare module 'ENTRY' {
import type { AppRouteModule } from 'next/dist/server/future/route-handlers/app-route-route-handler'

const handlers: AppRouteModule['handlers']
export = handlers
}

declare module 'CLIENT_MODULE' {
export const __turbopack_module_id__: string
}

declare module 'CLIENT_CHUNKS' {
const moduleId: string
export default moduleId

export const chunks: any[]
export const chunkListPath: string
}

0 comments on commit b95d678

Please sign in to comment.