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

fix trying to update unmounted input #3848

Conversation

AlbertLucianto
Copy link
Contributor

Should fix #3763

Referring to the issue, when an InlineComponent is rendered inside a slot, it is always instantiated and subscribes to the store without being mounted. As a result, when the store is updated it fails because it's trying to set the value to an unmounted input element.

I tried conditionally instantiating the default slot if custom slot is not given, but it breaks on nested-slot test case. So, I think the safest and simplest solution is to check whether the DOM element exists before updating the value.

It's my first time contribution, and really appreciate for your review! 😄

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR relates to an outstanding issue, so please reference it in your PR, or create an explanatory one for discussion. In many cases features are absent for a reason.
  • This message body should clearly illustrate what problems it solves. If there are related issues, remember to reference them.
  • Ideally, include a test that fails without this PR but passes with it. PRs will only be merged once they pass CI. (Remember to npm run lint!)

Tests

  • Run the tests tests with npm test or yarn test)

@Rich-Harris
Copy link
Member

Thank you for the PR! I think this is actually masking a deeper bug — in the original repro, this code gets generated for the Outer component:

function create_fragment(ctx) {
	var current;

	const default_slot_template = ctx.$$slots.default;
	const default_slot = create_slot(default_slot_template, ctx, null);

	var inner = new Inner({});

	return {...};
}

In other words, the Inner component gets instantiated no matter whether there's a default slot. Having been instantiated, it subscribes to the store, which triggers an invalidation that causes an update, but the update fails because the component was never 'created'.

So I think the solution here is to prevent that from happening, which may be slightly finicky — we'll see. I'll note this on #3763 and close this PR.

@Rich-Harris Rich-Harris closed this Nov 6, 2019
@AlbertLucianto AlbertLucianto deleted the fix/slots-with-default-value branch November 6, 2019 12:34
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.

Nested slots with default value and store: Cannot read property 'value' of undefined
2 participants