Skip to content

Explicit invalidation of resolved router data #24096

Closed as not planned
Closed as not planned

Description

@jonrimmer

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

The Angular router's resolve functionality does not seem to support a fundamental use-case: explicitly invalidating and refreshing some resolved data when the application knows it has changed.

For example, consider I have a route /project/:id with a resolver that loads the project data from an API and makes it available to a number of components in sub-pages.

Consider I also have a child page, "Rename Project", that makes a change via the API that invalidates the resolved project data. At this point, I need to force a reload that also refreshes the project data.

Or, consider I have a WebSocket connection that streams updates from the server and notifies my app when the project has been renamed by another user.

Navigating to another page will not re-run the resolver. Instead, the originally resolved data is returned. This caching is expected and helpful in most cases, but only if there is a way to invalidate the cached data when necessary.

Expected behavior

There should a way to tell the router to re-run a resolver when you know its data has changed. E.g. in my RenameProjectComponent controller:

async renameProject(newName: string) {
  await this.projectApi.renameProject(this.project.id, newName);
  this.activatedRoute.invalidateData('project');
  this.router.navigate(['project', this.project.id]);
}

The call to router.navigate(...) would then re-run the project resolver.

Minimal reproduction of the problem with instructions

https://stackblitz.com/edit/angular-dh291y

In this example, a "rename project" page changes the project entity in an underlying service. However, the original version of the entity provided by the resolver continues to be used, because there is no way for the app to signal to the router that it needs to fetch the updated project.

What is the motivation / use case for changing the behavior?

In the real world, data changes, and caches need to be invalidated. Without this ability, the Angular router's resolve functionality is little more than a toy.

Environment


Angular version: 6.0.0

Browser:

N/A

Activity

  1. added this to the needsTriage milestone on May 25, 2018
  2. added
    feature
    on Jun 5, 2018
  3. modified the milestones: needsTriage, Backlog on Jun 5, 2018
  4. liesahead commented on Sep 21, 2020

    @liesahead

    Well, 2 years.. Probably if status is set to medium it means it will never be implemented 😞

  5. angular-robot commented on Jun 5, 2021

    @angular-robot
    Contributor

    Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

    Find more details about Angular's feature request process in our documentation.

  6. angular-robot commented on Jun 25, 2021

    @angular-robot
    Contributor

    Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

    We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

    You can find more details about the feature request process in our documentation.

  7. angular-automatic-lock-bot commented on Jul 24, 2022

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  8. locked and limited conversation to collaborators on Jul 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: routerfeaturefreq2: medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions