Skip to content

Commit

Permalink
Merge branch 'canary' into add-logging-stable-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Jul 7, 2023
2 parents 17e6e41 + eb3d748 commit d328812
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ To access search params in [Pages](/docs/app/api-reference/file-conventions/page

Unlike Pages, [Layouts](/docs/app/api-reference/file-conventions/layout) (Server Components) **do not** receive the `searchParams` prop. This is because a shared layout is [not re-rendered during navigation](/docs/app/building-your-application/routing#partial-rendering) which could lead to stale `searchParams` between navigations. View [detailed explanation](/docs/app/api-reference/file-conventions/layout#layouts-do-not-receive-searchparams).

Instead, use the Page [`searchParams`](/docs/app/api-reference/file-conventions/page) prop or the [`useSearchParams`](/docs/app/api-reference/functions/use-params) hook in a Client Component, which is re-rendered on the client with the latest `searchParams`.
Instead, use the Page [`searchParams`](/docs/app/api-reference/file-conventions/page) prop or the [`useSearchParams`](/docs/app/api-reference/functions/use-search-params) hook in a Client Component, which is re-rendered on the client with the latest `searchParams`.

## Examples

Expand Down
14 changes: 4 additions & 10 deletions packages/next-swc/crates/next-core/src/app_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ async fn next_client_transition(
project_path,
server_root,
client_compile_time_info.environment(),
ty,
);
let client_module_options_context = get_client_module_options_context(
project_path,
Expand Down Expand Up @@ -277,7 +276,7 @@ fn next_edge_route_transition(
project_path,
output_path.join("edge"),
output_path.join("edge/chunks"),
get_client_assets_path(server_root, Value::new(ClientContextType::App { app_dir })),
get_client_assets_path(server_root),
edge_compile_time_info.environment(),
)
.reference_chunk_source_maps(should_debug("app_source"))
Expand Down Expand Up @@ -317,7 +316,7 @@ fn next_edge_page_transition(
project_path,
output_path.join("edge-pages"),
output_path.join("edge-pages/chunks"),
get_client_assets_path(server_root, Value::new(ClientContextType::App { app_dir })),
get_client_assets_path(server_root),
edge_compile_time_info.environment(),
)
.layer("ssr")
Expand Down Expand Up @@ -1112,7 +1111,7 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
project_path,
intermediate_output_path,
intermediate_output_path.join("chunks"),
get_client_assets_path(server_root, Value::new(ClientContextType::App { app_dir })),
get_client_assets_path(server_root),
context.compile_time_info().environment(),
)
.layer("ssr")
Expand Down Expand Up @@ -1207,12 +1206,7 @@ impl AppRouteVc {
this.project_path,
this.intermediate_output_path,
this.intermediate_output_path.join("chunks"),
get_client_assets_path(
this.server_root,
Value::new(ClientContextType::App {
app_dir: this.app_dir,
}),
),
get_client_assets_path(this.server_root),
this.context.compile_time_info().environment(),
)
.layer("ssr")
Expand Down
1 change: 0 additions & 1 deletion packages/next-swc/crates/next-core/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub async fn get_fallback_page(
project_path,
dev_server_root,
client_compile_time_info.environment(),
ty,
);
let entries =
get_client_runtime_entries(project_path, env, ty, mode, next_config, execution_context);
Expand Down
26 changes: 6 additions & 20 deletions packages/next-swc/crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,37 +312,23 @@ pub fn get_client_asset_context(
#[turbo_tasks::function]
pub fn get_client_chunking_context(
project_path: FileSystemPathVc,
server_root: FileSystemPathVc,
client_root: FileSystemPathVc,
environment: EnvironmentVc,
ty: Value<ClientContextType>,
) -> ChunkingContextVc {
DevChunkingContextVc::builder(
project_path,
server_root,
match ty.into_value() {
ClientContextType::Pages { .. }
| ClientContextType::App { .. }
| ClientContextType::Fallback => server_root.join("/_next/static/chunks"),
ClientContextType::Other => server_root.join("/_chunks"),
},
get_client_assets_path(server_root, ty),
client_root,
client_root.join("/_next/static/chunks"),
get_client_assets_path(client_root),
environment,
)
.hot_module_replacement()
.build()
}

#[turbo_tasks::function]
pub fn get_client_assets_path(
client_root: FileSystemPathVc,
ty: Value<ClientContextType>,
) -> FileSystemPathVc {
match ty.into_value() {
ClientContextType::Pages { .. }
| ClientContextType::App { .. }
| ClientContextType::Fallback => client_root.join("/_next/static/media"),
ClientContextType::Other => client_root.join("/_assets"),
}
pub fn get_client_assets_path(client_root: FileSystemPathVc) -> FileSystemPathVc {
client_root.join("/_next/static/media")
}

#[turbo_tasks::function]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ impl NextClientChunksTransitionVc {
project_path,
server_root,
client_compile_time_info.environment(),
ty,
);

let client_module_options_context = get_client_module_options_context(
Expand Down
23 changes: 4 additions & 19 deletions packages/next-swc/crates/next-core/src/page_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ pub async fn create_page_source(
project_root,
client_root,
client_compile_time_info.environment(),
client_ty,
);

let client_runtime_entries = get_client_runtime_entries(
Expand Down Expand Up @@ -155,10 +154,7 @@ pub async fn create_page_source(
project_root,
node_root.join("edge"),
node_root.join("edge/chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
edge_compile_time_info.environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
Expand Down Expand Up @@ -360,10 +356,7 @@ async fn create_page_source_for_file(
project_path,
node_path,
node_path.join("chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
server_context.compile_time_info().environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
Expand All @@ -375,10 +368,7 @@ async fn create_page_source_for_file(
project_path,
data_node_path,
data_node_path.join("chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
server_context.compile_time_info().environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
Expand All @@ -388,7 +378,6 @@ async fn create_page_source_for_file(
project_path,
client_root,
client_context.compile_time_info().environment(),
Value::new(ClientContextType::Pages { pages_dir }),
);

let pathname = pathname_for_path(client_root, client_path, PathType::Page);
Expand Down Expand Up @@ -530,10 +519,7 @@ async fn create_not_found_page_source(
project_path,
node_path,
node_path.join("chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
server_context.compile_time_info().environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
Expand All @@ -543,7 +529,6 @@ async fn create_not_found_page_source(
project_path,
client_root,
client_context.compile_time_info().environment(),
Value::new(ClientContextType::Pages { pages_dir }),
);

let (page_asset, pathname) =
Expand Down
8 changes: 2 additions & 6 deletions packages/next-swc/crates/next-core/src/web_entry_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,8 @@ pub async fn create_web_entry_source(
mode,
next_config,
);
let chunking_context = get_client_chunking_context(
project_root,
client_root,
compile_time_info.environment(),
ty,
);
let chunking_context =
get_client_chunking_context(project_root, client_root, compile_time_info.environment());
let entries = get_web_runtime_entries(project_root, ty, mode, next_config, execution_context);

let runtime_entries = entries.resolve_entries(context);
Expand Down
18 changes: 7 additions & 11 deletions packages/next/src/build/webpack/loaders/next-app-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,16 @@ async function createTreeCodeFromPath(
}

// We need to resolve all parallel routes in this level.
const files = await fs.readdir(absoluteSegmentPath)
const files = await fs.opendir(absoluteSegmentPath)

const parallelSegments: string[] = ['children']

await Promise.all(
files.map(async (file) => {
const filePath = path.join(absoluteSegmentPath, file)
const stat = await fs.stat(filePath)

if (stat.isDirectory() && file.startsWith('@')) {
parallelSegments.push(file)
}
})
)
for await (const dirent of files) {
// Make sure name starts with "@" and is a directory.
if (dirent.isDirectory() && dirent.name.charCodeAt(0) === 64) {
parallelSegments.push(dirent.name)
}
}

return parallelSegments
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/lib/metadata/resolvers/resolve-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function getSocialImageFallbackMetadataBase(

if (isMetadataBaseMissing) {
Log.warnOnce(
`\nmetadata.metadataBase is not set for resolving social open graph or twitter images, fallbacks to "${fallbackMetadata.origin}". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase`
`\nmetadata.metadataBase is not set for resolving social open graph or twitter images, using "${fallbackMetadata.origin}". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase`
)
}

Expand Down
7 changes: 5 additions & 2 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ import { interopDefault } from './interop-default'
import { preloadComponent } from './preload-component'
import { FlightRenderResult } from './flight-render-result'
import { createErrorHandler } from './create-error-handler'
import { getShortDynamicParamType } from './get-short-dynamic-param-type'
import {
getShortDynamicParamType,
dynamicParamTypes,
} from './get-short-dynamic-param-type'
import { getSegmentParam } from './get-segment-param'
import { getCssInlinedLinkTags } from './get-css-inlined-link-tags'
import { getPreloadableFonts } from './get-preloadable-fonts'
Expand Down Expand Up @@ -324,7 +327,7 @@ export async function renderToHTMLOrFlight(
if (!value) {
// Handle case where optional catchall does not have a value, e.g. `/dashboard/[...slug]` when requesting `/dashboard`
if (segmentParam.type === 'optional-catchall') {
const type = getShortDynamicParamType(segmentParam.type)
const type = dynamicParamTypes[segmentParam.type]
return {
param: key,
value: null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { DynamicParamTypes, DynamicParamTypesShort } from './types'

export const dynamicParamTypes: Record<
DynamicParamTypes,
DynamicParamTypesShort
> = {
catchall: 'c',
'optional-catchall': 'oc',
dynamic: 'd',
}

/**
* Shorten the dynamic param in order to make it smaller when transmitted to the browser.
*/
export function getShortDynamicParamType(
type: DynamicParamTypes
): DynamicParamTypesShort {
switch (type) {
case 'catchall':
return 'c'
case 'optional-catchall':
return 'oc'
case 'dynamic':
return 'd'
default:
throw new Error('Unknown dynamic param type')
const short = dynamicParamTypes[type]
if (!short) {
throw new Error('Unknown dynamic param type')
}
return short
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('app dir - metadata missing metadataBase', () => {
await next.start()
await fetchViaHTTP(next.url, '/')
expect(next.cliOutput).toInclude(
'metadata.metadataBase is not set for resolving social open graph or twitter images, fallbacks to'
'metadata.metadataBase is not set for resolving social open graph or twitter images, using'
)
expect(next.cliOutput).toInclude(`"http://localhost:${port}`)
expect(next.cliOutput).toInclude(
Expand Down

0 comments on commit d328812

Please sign in to comment.