[fix] prefer context from constructor options (#6759)

pull/6764/head
Conduitry 3 years ago committed by GitHub
parent cfc880bb31
commit 67b53bfe6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -124,7 +124,7 @@ export function init(component, options, instance, create_fragment, not_equal, p
on_disconnect: [],
before_update: [],
after_update: [],
context: new Map(parent_component ? parent_component.$$.context : options.context || []),
context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
// everything else
callbacks: blank_object(),

@ -91,7 +91,7 @@ export function create_ssr_component(fn) {
const $$ = {
on_destroy,
context: new Map(parent_component ? parent_component.$$.context : context || []),
context: new Map(context || (parent_component ? parent_component.$$.context : [])),
// these will be immediately discarded
on_mount: [],

@ -0,0 +1,6 @@
<script>
import { getContext } from 'svelte';
const value = getContext('foo');
</script>
<div>Value in child component: {value}</div>

@ -0,0 +1,6 @@
export default {
skip_if_ssr: true,
html: `
<div><div>Value in child component: undefined</div></div>
`
};

@ -0,0 +1,15 @@
<script>
import { setContext } from 'svelte';
import ChildComponent from './ChildComponent.svelte';
setContext('foo', true);
function render(node) {
new ChildComponent({
target: node,
context: new Map()
});
}
</script>
<div use:render />

@ -0,0 +1,6 @@
<script>
import { getContext } from 'svelte';
const value = getContext('foo');
</script>
<div>Value in child component: {value}</div>

@ -0,0 +1 @@
<div><div>Value in child component: undefined</div></div>

@ -0,0 +1,10 @@
<script>
import { setContext } from 'svelte';
import ChildComponent from './ChildComponent.svelte';
setContext('foo', true);
const content = ChildComponent.render({}, { context: new Map() }).html;
</script>
<div>{@html content}</div>
Loading…
Cancel
Save