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

Ensure errors during component creation do not cause secondary errors during DOM cleanup #1073

Merged
merged 1 commit into from
Apr 16, 2020

Conversation

pzuraq
Copy link
Member

@pzuraq pzuraq commented Apr 16, 2020

Currently we don't do any cleanup in the event of an error occuring
during the actual execution of the VM. This can leave the VM in a bad
state, in particular the element builder, since it doesn't actually
finalize block nodes until after the entire block has executed. This
means that if an error occurs during the execution of a block, the
VM will never properly initialize those blocks, and their first and last
nodes will be null.

While we don't currently support recovering from this type of an error,
we do need to be able to cleanup the application after one, specifically
for tests. Previously, this worked no matter what because of the
Application Wrapper optional feature - there was always a root div
element that we could clear, so there was always a first and last node
for us to track. With the feature disabled, we started seeing failures
such as this issue within user tests.

This PR refactors VM updates, specifically, to allow them to properly
clean up the element builder on failures. It now closes all remaining
open blocks, finalizing them to ensure they have nodes.

This only works for VM updates because the initial append is an
iterator, which the user controls execution of. We'll need to have a
different strategy for this API, but it shouldn't be a regression at the
moment because any failures during the iteration will result in a
completely broken app from the get-go. There is no result, and no
accompanying destroy function, so existing tests and apps cannot be
affected by failures during append.

Currently we don't do any cleanup in the event of an error occuring
during the actual execution of the VM. This can leave the VM in a bad
state, in particular the element builder, since it doesn't actually
finalize block nodes until _after_ the entire block has executed. This
means that if an error occurs during the execution of a block, the
VM will never properly initialize those blocks, and their first and last
nodes will be `null`.

While we don't currently support recovering from this type of an error,
we do need to be able to cleanup the application after one, specifically
for tests. Previously, this worked no matter what because of the
Application Wrapper optional feature - there was always a root `div`
element that we could clear, so there was always a first and last node
for us to track. With the feature disabled, we started seeing failures
such as [this issue within user tests](emberjs/ember-test-helpers#768 (comment)).

This PR refactors VM updates, specifically, to allow them to properly
clean up the element builder on failures. It now closes all remaining
open blocks, finalizing them to ensure they have nodes.

This only works for VM updates because the initial append is an
_iterator_, which the user controls execution of. We'll need to have a
different strategy for this API, but it shouldn't be a regression at the
moment because any failures during the iteration will result in a
completely broken app from the get-go. There is no result, and no
accompanying `destroy` function, so existing tests and apps cannot be
affected by failures during append.
@@ -90,7 +90,7 @@ export interface ElementBuilder extends Cursor, DOMStack, TreeOperations {
constructing: Option<SimpleElement>;
element: SimpleElement;

block(): LiveBlock;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was dead code

@@ -165,10 +164,6 @@ export default abstract class VM<C extends JitOrAotBlock> implements PublicVM, I
return this[INNER_VM].stack as EvaluationStack;
}

currentBlock(): LiveBlock {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was dead code

@rwjblue rwjblue changed the title [BUGFIX] Properly cleanup the element builder in a try/finally Ensure errors during component creation does not cause secondary errors during DOM cleanup Apr 16, 2020
@rwjblue rwjblue changed the title Ensure errors during component creation does not cause secondary errors during DOM cleanup Ensure errors during component creation do not cause secondary errors during DOM cleanup Apr 16, 2020
@rwjblue rwjblue added the bug label Apr 16, 2020
@rwjblue rwjblue merged commit c1dce1b into master Apr 16, 2020
@rwjblue rwjblue deleted the bugfix/properly-try-finally-element-builder branch April 16, 2020 14:05
rwjblue added a commit to emberjs/ember.js that referenced this pull request Apr 16, 2020
…g cleanup).

Changelog from the release:

* `@glimmer/integration-tests`, `@glimmer/interfaces`, `@glimmer/runtime`
  * [#1073](glimmerjs/glimmer-vm#1073) Ensure errors during component creation do not cause secondary errors during DOM cleanup ([@pzuraq](https://github.com/pzuraq))

- Chris Garrett ([@pzuraq](https://github.com/pzuraq))
rwjblue added a commit to emberjs/ember.js that referenced this pull request Apr 16, 2020
Backport of the changes in
[glimmerjs/glimmer-vm#1073](glimmerjs/glimmer-vm#1073)
to 0.38.5-alpha branch (used by ember-source@3.16).
rwjblue added a commit to emberjs/ember.js that referenced this pull request Apr 23, 2020
…g cleanup).

Changelog from the release:

* `@glimmer/integration-tests`, `@glimmer/interfaces`, `@glimmer/runtime`
  * [#1073](glimmerjs/glimmer-vm#1073) Ensure errors during component creation do not cause secondary errors during DOM cleanup ([@pzuraq](https://github.com/pzuraq))

- Chris Garrett ([@pzuraq](https://github.com/pzuraq))

(cherry picked from commit cf4a4bc)
kiwiupover added a commit to kiwiupover/ember-render-modifiers that referenced this pull request Aug 3, 2021
   This PR fixed an issue that causes and error to be thrown twice
   for ember versions <= 3.15
   glimmerjs/glimmer-vm#1073
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants