-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Incorrect context in child component inside await #2443
Comments
The global The |
@EmilTholin This issue is biting me when trying to use the I thought about raising this in |
Is there any known workaround to this issue other than simply not using context at all? |
I'd argue that not using |
Naive fix: diff --git a/src/runtime/internal/await_block.ts b/src/runtime/internal/await_block.ts
index 3834ff7c..14f68d5c 100644
--- a/src/runtime/internal/await_block.ts
+++ b/src/runtime/internal/await_block.ts
@@ -1,4 +1,5 @@
import { assign, is_promise } from './utils';
+import { get_current_component, set_current_component } from './lifecycle';
import { check_outros, group_outros, transition_in, transition_out } from './transitions';
import { flush } from './scheduler';
@@ -40,9 +41,12 @@ export function handle_promise(promise, info) {
}
if (is_promise(promise)) {
+ const current_component = get_current_component();
promise.then(value => {
+ set_current_component(current_component);
update(info.then, 1, info.value, value);
}, error => {
+ set_current_component(current_component);
update(info.catch, 2, info.error, error);
});
diff --git a/src/runtime/internal/lifecycle.ts b/src/runtime/internal/lifecycle.ts
index d659fd2e..0ca3e430 100644
--- a/src/runtime/internal/lifecycle.ts
+++ b/src/runtime/internal/lifecycle.ts
@@ -6,7 +6,7 @@ export function set_current_component(component) {
current_component = component;
}
-function get_current_component() {
+export function get_current_component() {
if (!current_component) throw new Error(`Function called outside component initialization`);
return current_component;
} This doesn't break any existing tests, and at first glance seems to fix the issue here. I have no idea whether this is a good idea. |
Fixed in 3.9.1, thanks |
REPL
The text was updated successfully, but these errors were encountered: