Skip to content

Commit

Permalink
fix(router): Should not freeze original object used for route data (#…
Browse files Browse the repository at this point in the history
…53635)

This was broken in 3278966 where the
new code fails to copy the data object when not inheriting data.

fixes #53632

PR Close #53635
  • Loading branch information
atscott committed Dec 19, 2023
1 parent b131c3b commit 0696ab6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/router/src/router_state.ts
Expand Up @@ -265,8 +265,8 @@ export function getInherited(
};
} else {
inherited = {
params: route.params,
data: route.data,
params: {...route.params},
data: {...route.data},
resolve: {...route.data, ...(route._resolvedData ?? {})}
};
}
Expand Down
10 changes: 10 additions & 0 deletions packages/router/test/recognize.spec.ts
Expand Up @@ -31,6 +31,16 @@ describe('recognize', async () => {
expect(Object.isFrozen(child.params)).toBeTruthy();
});

it('should freeze data object (but not original route data)', async () => {
const someData = {a: 1};
const s: RouterStateSnapshot =
await recognize([{path: '**', component: ComponentA, data: someData}], 'a');
checkActivatedRoute(s.root, '', {}, RootComponent);
const child = s.root.firstChild!;
expect(Object.isFrozen(child.data)).toBeTruthy();
expect(Object.isFrozen(someData)).toBeFalsy();
});

it('should support secondary routes', async () => {
const s: RouterStateSnapshot = await recognize(
[
Expand Down

0 comments on commit 0696ab6

Please sign in to comment.