Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NP-6345] Prevent detail views from recursively rendering #1339

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

KernelDeimos
Copy link
Collaborator

@KernelDeimos KernelDeimos commented Jan 18, 2022

It is possible for properties to be recursive, and these properties crash detail views.

For example, the factory for view on a foam.nanos.menu.Menu introduces recursion:

factory: function() { return { class: 'foam.u2.view.MenuView', menu: this }; }

What Won't Work

There is a very narrow subset of appropriate solutions to this problem. Here are just a few things that don't work:

  • A low-level solution, such as a Context decorator to prevent duplicate data references, would prevent the flexibility to have the same data passed to child views.
  • Taking into account the data plus the class of the view would seem to avoid repetition, but some views may display different information for the same data depending on other view properties. (looking at you, SectionView)
  • Taking into account all properties of a view will not prevent infinite recursion. Maybe one property is a sequence number or randomly generated value.

The only general solution for all views would then involve detecting whether the render function of a view will halt or not. This we know to be impossible, as it is the definition of the Halting Problem.

What Did Work

While there's no solution for all views, infinite recursion can be avoided on a subset of views with known behaviour. Providing a convention and tools to handle this will allow anyone to add a view to this subset.

This PR adds a referencePath context value.

  • Every detail view adds its data to this path.
  • Every detail view, when rendering a property, uses RecursionSafePropertyView
  • MapView, and any view we want to be safe from recursion, also checks this path

Example introducing recursion to a property:
image

Example of detail view for this property:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant