Skip to content

Commit

Permalink
rename entry directive
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Sep 12, 2022
1 parent 688a011 commit 90a3618
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 21 deletions.
18 changes: 6 additions & 12 deletions packages/next/build/webpack/loaders/next-flight-loader/index.ts
@@ -1,4 +1,5 @@
import path from 'path'
import { RSC_CLIENT_ENTRY } from '../../../../shared/lib/constants'
import { checkExports } from '../../../analysis/get-page-static-info'
import { parse } from '../../../swc'

Expand All @@ -18,11 +19,6 @@ function transformServer(source: string, isESModule: boolean) {
)
}

const FLIGHT_TYPE = {
server: 'server-entry',
client: 'client-entry',
} as const

function containsPath(parent: string, child: string) {
const relation = path.relative(parent, child)
return !!relation && !relation.startsWith('..') && !path.isAbsolute(relation)
Expand Down Expand Up @@ -64,18 +60,16 @@ export default async function transformSource(

const isResourcePageOrLayoutFile = isPageOrLayoutFile(this.resourcePath)

// Assign the rsc module type to buildInfo, by default is server-entry
buildInfo.rsc = {
type: FLIGHT_TYPE.server,
}
// Assign the RSC meta information to buildInfo.
buildInfo.rsc = {}
for (const node of firstTwoNodes) {
if (
node.type === 'ExpressionStatement' &&
node.expression.type === 'StringLiteral'
) {
if (node.expression.value === FLIGHT_TYPE.client) {
if (node.expression.value === RSC_CLIENT_ENTRY) {
// Detect client entry
buildInfo.rsc.type = FLIGHT_TYPE.client
buildInfo.rsc.type = RSC_CLIENT_ENTRY
break
}
}
Expand All @@ -94,7 +88,7 @@ export default async function transformSource(
}
}

if (buildInfo.rsc.type === FLIGHT_TYPE.client) {
if (buildInfo.rsc.type === RSC_CLIENT_ENTRY) {
errorForInvalidDataFetching(this.emitError)
const code = transformClient(this.resourcePath)
return code
Expand Down
7 changes: 5 additions & 2 deletions packages/next/build/webpack/plugins/flight-manifest-plugin.ts
Expand Up @@ -6,7 +6,10 @@
*/

import { webpack, sources } from 'next/dist/compiled/webpack/webpack'
import { FLIGHT_MANIFEST } from '../../../shared/lib/constants'
import {
FLIGHT_MANIFEST,
RSC_CLIENT_ENTRY,
} from '../../../shared/lib/constants'
import { relative } from 'path'

// This is the module that will be used to anchor all client references to.
Expand Down Expand Up @@ -176,7 +179,7 @@ export class FlightManifestPlugin {
// That way we know by the type of dep whether to include.
// It also resolves conflicts when the same module is in multiple chunks.
const rscType = mod.buildInfo.rsc?.type
if (rscType !== 'client-entry') return
if (rscType !== RSC_CLIENT_ENTRY) return

if (/\/(page|layout)\.(ts|js)x?$/.test(resource)) {
entryFilepath = resource
Expand Down
2 changes: 1 addition & 1 deletion packages/next/client/components/app-router.client.tsx
@@ -1,4 +1,4 @@
'client-entry'
'client'

export const time = '1'

Expand Down
2 changes: 1 addition & 1 deletion packages/next/client/components/hot-reloader.client.tsx
@@ -1,4 +1,4 @@
'client-entry'
'client'

import {
useCallback,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/client/components/layout-router.client.tsx
@@ -1,4 +1,4 @@
'client-entry'
'client'

import React, { useContext, useEffect, useRef } from 'react'
import type {
Expand Down
2 changes: 2 additions & 0 deletions packages/next/shared/lib/constants.ts
Expand Up @@ -95,6 +95,8 @@ export const OPTIMIZED_FONT_PROVIDERS = [
export const STATIC_STATUS_PAGES = ['/500']
export const TRACE_OUTPUT_VERSION = 1

export const RSC_CLIENT_ENTRY = 'client'

// comparing
// https://nextjs.org/docs/api-reference/edge-runtime
// with
Expand Down
5 changes: 2 additions & 3 deletions packages/next/taskfile-swc.js
Expand Up @@ -111,11 +111,10 @@ module.exports = function (task) {
const originalSource = file.data.toString('utf-8')
let output = yield transform(originalSource, options)

const hasClientEntry = /^['"]client-entry['"]/.test(originalSource)
const hasClientEntry = /^['"]client['"]/.test(originalSource)
if (options.filename.includes('.client.')) {
console.log('hasClientEntry', options.filename, hasClientEntry)
output.code =
(hasClientEntry ? `"client-entry";\n` : '\n') + output.code
output.code = (hasClientEntry ? `"client";\n` : '\n') + output.code
}

const ext = path.extname(file.base)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/convention/app/client/page.js
@@ -1,5 +1,5 @@
// bar/page.js should work with client hook
'client-entry'
'client'

import { useState } from 'react'

Expand Down

0 comments on commit 90a3618

Please sign in to comment.