Commit Graph

1409 Commits

Author SHA1 Message Date
Tobias Koppers 907bf470eb Turbopack: reduce tasks needed for emitting (#68212)
### What?

Reduce the number of tasks needed for emitting. Simplify emitting.

Reverts #62324

Closes PACK-2564

fixes PACK-2552
2024-07-31 22:37:46 +02:00
Tobias Koppers 3eb38a9c75 fix renaming of page files, add handling of symlinked pages (#68195)
### What?

When renaming a page from `page.js` to `page.tsx` it can temporarily
have both variants which end up writing the same files.

Also fixes symlinked page files

Depends on https://github.com/vercel/turbo/pull/8851

fixes PACK-2718
2024-07-31 21:38:22 +02:00
Janka Uryga 4db8f30667 next/form (#68102)
## What

This PR introduces `<Form>`, a form component integrated with the
Next.js router.

Form has two modes of operation.

### When `action` is a path/url

```jsx
<Form action="/search">
```

In essence, this is a progressively enhanced GET form. 
- it will prefetch the target route (or, more commonly in this case, its
loading state)
- when submitted, it will perform a **client navigation** to the target
URL, encoding input fields from the form into the URL as search params.

### When `action` is a function

```jsx
<Form action={myReactAction}>
```

This is a progressively enhanced POST form. In this case, `<Form>` will
act just like `<form>` (i.e. execute the action function when
submitted). This is mostly here for convenience/consistency with React.

## Notes

### Notable props (or lack thereof)

- `replace` - same as Link, call `router.replace` instead of
`router.push` when navigating. This only works in "GET mode".
- `scroll` - same as Link, control the `scroll` option of router when
navigating. This only works in "GET mode".
- `onSubmit` - same as the usual, but notably, **calling
`event.preventDefault()` inside it will prevent Next from navigating**
(this matches how Link's `onClick` works)

We disallow passing certain form props (`method`, `encType`, `target`)
because both the GET and POST cases have specific requirements for these
that can't be overridden.

There is currently no way to control/disable the prefetching behavior
(like `<Link prefetch={false}>`) or render a custom component instead of
`<form>` (like Link's `passHref` behavior). These may be added in the
future.

### Submitter overrides

We have partial support for overriding the `action` via
```jsx
<button type="submit" formAction="/other-search">
```

It will also client-navigate, but can't be prefetched (because we don't
know the route to prefetch until a submit occurs), so this isn't really
recommended (unless the prefetch is triggered in some other way).

Unfortunately, just like `formAction`, all of the "banned" props
mentioned in the previous section (`method`, `encType`, `target`) are
overridable by the submitting element (the
["submitter"](https://developer.mozilla.org/en-US/docs/Web/API/SubmitEvent/submitter))
via `formMethod` , `formEncType` and `formTarget` respectively. We don't
have a good way of banning these within a `<Form>`, because we don't
have control over `<button>` props. So in this case the best we can do
is just warn and fall back to native browser behavior (because this is
what'd happen before hydration). Which means that **if the submitter
specifies a `formMethod` , `formEncType` and `formTarget` that Form
don't support, we will not client-navigate.**

### handling `<input type="file">`

Surprisingly, this works in a url-encoded form, even if it makes very
little sense. But same as submitter props, we have no good way of
banning it, so we match the browser behavior and submit _the filename_
instead of the file object.
2024-07-30 17:45:29 +02:00
Niklas Mischkulnig 16a55ae8a3 Apply serverExternalPackages inside node_modules and add keyv (#67948)
ExternalCjsModulesResolvePlugin was originally disabled for requests
inside node_modules (e.g. from inside `cacheable-request` to `keyv`) by
@sokra in https://github.com/vercel/turbo/pull/3736.
But it seems that we do want this to happen

In the `ExternalPredicate::AllExcept` case, requests inside node_modules
are still ignored. Otherwise
`next/dist/compiled/next-server/pages.runtime.dev.js` was marked as
external and failed many tests

With that fixed, add `keyv` so that `got` can be imported.

Fixes #67282
Fixes PACK-3139
2024-07-25 14:03:42 +02:00
Donny/강동윤 29c23b263f fix: Use [ and ] instead of ( and ) for debug transform (#68142)
### What?

Use `[]` instead of `()` for call stack.

### Why?

https://github.com/vercel/next.js/pull/68056#discussion_r1690601277

### How?
2024-07-25 08:24:26 +00:00
Tobias Koppers 6af8da5875 update turbopack (#68129)
* https://github.com/vercel/turbo/pull/8812 <!-- Benjamin Woodruff -
Simplify some of the syntax used with VcRead<T> -->
* https://github.com/vercel/turbo/pull/8823 <!-- hrmny -
feat(turbopack): support analysing string concatenation -->
* https://github.com/vercel/turbo/pull/8828 <!-- Tobias Koppers - change
from failsafe_analyse to failsafe_parse -->
* https://github.com/vercel/turbo/pull/8831 <!-- Alexander Lyon - make
sure that all the taiki-e/install-action calls use our env -->
* https://github.com/vercel/turbo/pull/8819 <!-- Tobias Koppers -
Refactor cell reading to handle removed cells -->
* https://github.com/vercel/turbo/pull/8038 <!-- Alexander Lyon - add
tags to turbo tasks -->
* https://github.com/vercel/turbo/pull/8807 <!-- Tobias Koppers - box
Scheduled task state to save memory -->
* https://github.com/vercel/turbo/pull/8170 <!-- Tobias Koppers - Drop
excessive cells after task reexecution -->
2024-07-25 06:30:42 +00:00
Donny/강동윤 af6aa786b9 feat(next-swc): Add a transform adding function names (#68056)
### What?

Implements a transform that adds readable names to anonymous function
expressions in react component functions.

Adding `{ debugFunctionName: true }` to swcOptions will do the trick.

### Why?

x-ref: https://vercel.slack.com/archives/C04TR3U872A/p1721702161121619


### How?
2024-07-24 21:01:59 +09:00
Will Binns-Smith 42c991ffc0 Prevent unnecessary rsc reloads on navigation (#68049)
In larger apps, when compilation can take time and endpoints are often
build concurrently, `endpoint_server_changed_subscribe`’s subscription
to turbotasks can result in unnecessary calls of the JS callback even
when turbotasks input has not changed.

This wraps subscribing to issues and diagnostics in
`endpoint_server_changed_subscribe` within a turbotasks function that
ensures that inputs are properly consistent (e.g. diagnostics have been
sorted and are value-equal) so this callback is not called unnecessary.

Test Plan: Navigate within a large app and verify
`serverComponentChanges` messages are not sent through the web socket
connection and the browser does not perform unnecessary fetch requests
to rsc endpoints.

### Turbopack Changes

* https://github.com/vercel/turbo/pull/8777 <!-- Tobias Koppers - merge
InProgressDirty into InProgress -->
* https://github.com/vercel/turbo/pull/8785 <!-- Tobias Koppers - fix
watcher bug with file creation -->
* https://github.com/vercel/turbo/pull/8793 <!-- Tobias Koppers - get
rid of notify-debouncer in favor of our own debouncing -->
* https://github.com/vercel/turbo/pull/8805 <!-- Tobias Koppers - impl
Ord for Diagnostics and Issue so they are sorted correctly -->

---------

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2024-07-23 13:43:34 +02:00
hrmny cad3a51049 refactor: move rust crates to the repo root directory (#67780)
### Why?
In preparation for moving all turbopack crates

Also makes them easier to work with in general.

Closes PACK-3164
2024-07-22 18:41:27 +02:00