Opening this PR for discussion, I'm very open to scope changes.
This PR tackles two problems with `defaultStructuralSharing: true`:
1. symbol properties are not taken into account for "object equality"
and are not copied over when creating a new copy
2. non-enumerable properties are not taken into account for "object
equality" and are not copied over when creating a new copy
Point 1. actually is causing some of our users a headache, see
https://github.com/apollographql/apollo-client/issues/12619 and
https://community.apollographql.com/t/preloadquery-with-tanstack-router-loader/9100
.
Users expect that they're able to pass an object with symbol properties
over from a loader into components, but when having
`defaultStructuralSharing` enabled, from the second object that is
passed over, it creates a copy and strips off symbol properties.
That new object without the expected symbol properties will then crash
our `useReadQuery` hook.
In other words, the first loader call returns
```js
{
refObject: { toPromise: Function1, [secretSymbol]: ImplementationDetail1 }
}
```
the component receives
```js
{
refObject: { toPromise: Function1, [secretSymbol]: ImplementationDetail1 }
}
```
and the second loader call returns
```js
{
refObject: { toPromise: Function2, [secretSymbol]: ImplementationDetail2 }
}
```
but the component receives
```js
{
refObject: { toPromise: Function2 }
}
```
`toPromise` is a different function, so it goes into the "clone" path,
but skips the `secretSymbol` property.
If we wouldn't have that `toPromise` property on there (and we're
considering removing it!), it would even be worse to debug - users would
always stay on the first `refObject` and never get the second, since
both objects would be considered equal.
On our side, passing these objects from loaders to components is
actually an intended pattern, so this is causing quite a bit of problems
- see this example from our docs (see [Initiating queries outside
React](https://www.apollographql.com/docs/react/data/suspense#initiating-queries-outside-react)):
```ts
import { useLoaderData } from 'react-router-dom';
export function loader() {
return preloadQuery(GET_DOGS_QUERY);
}
export function RouteComponent() {
const queryRef = useLoaderData();
const { data } = useReadQuery(queryRef);
return (
// ...
);
}
```
Problem 2. is purely hypothetical and we haven't encountered it - but it
should probably be handled in some way.
Both of these problems can be handled in two ways:
* take these "special properties" into account for comparisons and copy
them over (my naive approach here would lose the "non-enumerability" of
these properties, more code would be necessary to keep that)
* in `isPlainObject` just return `false` if an object has non-enumerable
or symbol properties. This would opt out of structural sharing for these
objects (which is probably perfectly fine)
I'd be open for either of those solutions, and also for completely
dropping the "non-enumerable" case for simplicity, but I would be very
happy if we could get *something* in to help with symbol properties.
In React Query, these values can be assumed to be serializable JSON, so
the current implementation is perfectly fine, but with client-side
loaders, users can just pass anything, and here it's causing quite the
problem.
Telling our users to situationally turn off structural sharing would be
an educational nightmare.
This allows `Route.Link` and `routeApi.Link` bindings instead of manual
`from`.
We never used to be able to do this due to circular issues but it seems
this is no longer an issue since all the changes to the types
---------
Co-authored-by: TkDodo <office@dorfmeister.cc>
# Add DevJokes Tutorial: Reading and Writing Files
<img width="1318" alt="image"
src="https://github.com/user-attachments/assets/e6284dea-9596-42e5-b37a-c29ed56fa934"
/>
## Description
Adds a tutorial showing how to build a full-stack DevJokes app with
TanStack Start. Users learn to create server functions for reading and
writing to files, build React components, and implement data fetching
with TanStack Router.
## Key Features
- Server functions with `createServerFn`
- File-based data storage with Node.js `fs`
- Form handling and data validation
- Data refreshing with `router.invalidate()`
- Complete UI with Tailwind CSS
## Demo
https://youtu.be/zd0rtKbtlgU
## Reference
Complete code available at: https://github.com/shrutikapoor08/devjokes
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Add a button to navigate to a route from the `router-devtools`.
Paths with dynamic path parameters will reuse the path parameters
from the current route. Only paths, where the current path
parameters are viable for a successful navigation will have this button
appear.
---
Co-authored-by: SeanCassiere <33615041+SeanCassiere@users.noreply.github.com>