Skip to content

Commit

Permalink
(react): Fix missing meta and mutation bugs (#5833)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaance committed Mar 16, 2023
1 parent b485b85 commit 12e5aa6
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions packages/remix-react/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,28 @@ function V2Meta() {
let routeModule = routeModules[routeId];
let routeMeta: V2_MetaDescriptor[] | V1_HtmlMetaDescriptor | undefined = [];

let match: V2_MetaMatch = {
id: routeId,
data,
meta: [],
params: _match.params,
pathname: _match.pathname,
handle: _match.route.handle,
// TODO: Remove in v2. Only leaving it for now because we used it in
// examples and there's no reason to crash someone's build for one line.
// They'll get a TS error from the type updates anyway.
// @ts-expect-error
get route() {
console.warn(
"The meta function in " +
_match.route.path +
" accesses the `route` property on `matches`. This is deprecated and will be removed in Remix version 2. See"
);
return _match.route;
},
};
matches[i] = match;

if (routeModule?.meta) {
routeMeta =
typeof routeModule.meta === "function"
Expand All @@ -676,12 +698,14 @@ function V2Meta() {
location,
matches,
})
: Array.isArray(routeModule.meta)
? [...routeModule.meta]
: routeModule.meta;
} else if (leafMeta) {
// We only assign the route's meta to the nearest leaf if there is no meta
// export in the route. The meta function may return a falsey value which
// is effectively the same as an empty array.
routeMeta = leafMeta;
routeMeta = [...leafMeta];
}

routeMeta = routeMeta || [];
Expand All @@ -697,28 +721,9 @@ function V2Meta() {
);
}

let match: V2_MetaMatch = {
id: routeId,
data,
meta: routeMeta,
params: _match.params,
pathname: _match.pathname,
handle: _match.route.handle,
// TODO: Remove in v2. Only leaving it for now because we used it in
// examples and there's no reason to crash someone's build for one line.
// They'll get a TS error from the type updates anyway.
// @ts-expect-error
get route() {
console.warn(
"The meta function in " +
_match.route.path +
" accesses the `route` property on `matches`. This is deprecated and will be removed in Remix version 2. See"
);
return _match.route;
},
};
match.meta = routeMeta;
matches[i] = match;
meta = routeMeta;
meta = [...routeMeta];
leafMeta = meta;
}

Expand Down

0 comments on commit 12e5aa6

Please sign in to comment.