Skip to content

Commit c1ef7d7

Browse files
committed
chore: prevent usage of getContext during component template
1 parent 02441c6 commit c1ef7d7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.changeset/young-pillows-join.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
chore: prevent usage of getContext during component template

packages/svelte/src/internal/client/runtime.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,11 @@ export function getAllContexts() {
949949
/** @returns {Map<unknown, unknown>} */
950950
function get_or_init_context_map() {
951951
const component_context = current_component_context;
952-
if (component_context === null) {
952+
if (
953+
component_context === null ||
954+
current_effect === null ||
955+
(current_effect.f & BRANCH_EFFECT) === 0
956+
) {
953957
throw new Error(
954958
'ERR_SVELTE_ORPHAN_CONTEXT' +
955959
(DEV ? 'Context can only be used during component initialisation.' : '')

0 commit comments

Comments
 (0)