nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: libp2p/go-libp2p
Pull request #853 (2020-03-24 23:49:43)

fix: set the private key when constructing the autonat service
Otherwise, it the node fails to build.


Patch:
diff --git a/config/config.go b/config/config.go
index bd843cac..f491f92d 100644
--- a/config/config.go
+++ b/config/config.go
@@ -2,6 +2,7 @@ package config
 
 import (
 	"context"
+	"crypto/rand"
 	"fmt"
 
 	"github.com/libp2p/go-libp2p-core/connmgr"
@@ -283,6 +284,11 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
 		return addrF(h.AllAddrs())
 	})}
 	if cfg.AutoNATService {
+		autonatPrivKey, _, err := crypto.GenerateEd25519Key(rand.Reader)
+		if err != nil {
+			return nil, err
+		}
+
 		// Pull out the pieces of the config that we _actually_ care about.
 		// Specifically, don't setup things like autorelay, listeners,
 		// identify, etc.
@@ -294,9 +300,11 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
 			PSK:                cfg.PSK,
 			Filters:            cfg.Filters,
 			Reporter:           cfg.Reporter,
+			PeerKey:            autonatPrivKey,
 
 			Peerstore: pstoremem.NewPeerstore(),
 		}
+
 		dialer, err := autoNatCfg.makeSwarm(ctx)
 		if err != nil {
 			h.Close()


Test patch:
diff --git a/libp2p_test.go b/libp2p_test.go
index d1099c64..9a8e4b80 100644
--- a/libp2p_test.go
+++ b/libp2p_test.go
@@ -77,6 +77,15 @@ func TestInsecure(t *testing.T) {
 	h.Close()
 }
 
+func TestAutoNATService(t *testing.T) {
+	ctx := context.Background()
+	h, err := New(ctx, EnableNATService())
+	if err != nil {
+		t.Fatal(err)
+	}
+	h.Close()
+}
+
 func TestDefaultListenAddrs(t *testing.T) {
 	ctx := context.Background()
Repository: libp2p/go-libp2p
Pull request #948 (2020-05-20 18:09:31)

fix: fix connection gater in transport constructor


Patch:
diff --git a/config/constructor_types.go b/config/constructor_types.go
index 34bcba8e..3374786e 100644
--- a/config/constructor_types.go
+++ b/config/constructor_types.go
@@ -28,12 +28,12 @@ var (
 	privKeyType   = reflect.TypeOf((*crypto.PrivKey)(nil)).Elem()
 	pubKeyType    = reflect.TypeOf((*crypto.PubKey)(nil)).Elem()
 	pstoreType    = reflect.TypeOf((*peerstore.Peerstore)(nil)).Elem()
+	connGaterType = reflect.TypeOf((*connmgr.ConnectionGater)(nil)).Elem()
 
 	// concrete types
-	peerIDType    = reflect.TypeOf((peer.ID)(""))
-	upgraderType  = reflect.TypeOf((*tptu.Upgrader)(nil))
-	pskType       = reflect.TypeOf((pnet.PSK)(nil))
-	connGaterType = reflect.TypeOf((*connmgr.ConnectionGater)(nil))
+	peerIDType   = reflect.TypeOf((peer.ID)(""))
+	upgraderType = reflect.TypeOf((*tptu.Upgrader)(nil))
+	pskType      = reflect.TypeOf((pnet.PSK)(nil))
 )
 
 var argTypes = map[reflect.Type]constructor{
diff --git a/config/reflection_magic.go b/config/reflection_magic.go
index 30609a80..acaaca04 100644
--- a/config/reflection_magic.go
+++ b/config/reflection_magic.go
@@ -121,7 +121,14 @@ func makeConstructor(
 	return func(h host.Host, u *tptu.Upgrader, cg connmgr.ConnectionGater) (interface{}, error) {
 		arguments := make([]reflect.Value, len(argConstructors))
 		for i, makeArg := range argConstructors {
-			arguments[i] = reflect.ValueOf(makeArg(h, u, cg))
+			if arg := makeArg(h, u, cg); arg != nil {
+				arguments[i] = reflect.ValueOf(arg)
+			} else {
+				// ValueOf an un-typed nil yields a zero reflect
+				// value. However, we _want_ the zero value of
+				// the _type_.
+				arguments[i] = reflect.Zero(t.In(i))
+			}
 		}
 		return callConstructor(v, arguments)
 	}, nil


Test patch:
diff --git a/libp2p_test.go b/libp2p_test.go
index 9a8e4b80..3676e528 100644
--- a/libp2p_test.go
+++ b/libp2p_test.go
@@ -7,10 +7,14 @@ import (
 	"strings"
 	"testing"
 
+	"github.com/libp2p/go-libp2p-core/connmgr"
 	"github.com/libp2p/go-libp2p-core/crypto"
 	"github.com/libp2p/go-libp2p-core/host"
 	"github.com/libp2p/go-libp2p-core/peer"
+	"github.com/libp2p/go-libp2p-core/transport"
 	"github.com/libp2p/go-tcp-transport"
+
+	tptu "github.com/libp2p/go-libp2p-transport-upgrader"
 )
 
 func TestNewHost(t *testing.T) {
@@ -33,6 +37,22 @@ func TestBadTransportConstructor(t *testing.T) {
 	}
 }
 
+func TestTransportConstructor(t *testing.T) {
+	ctx := context.Background()
+	ctor := func(
+		h host.Host,
+		_ connmgr.ConnectionGater,
+		upgrader *tptu.Upgrader,
+	) transport.Transport {
+		return tcp.NewTCPTransport(upgrader)
+	}
+	h, err := New(ctx, Transport(ctor))
+	if err != nil {
+		t.Fatal(err)
+	}
+	h.Close()
+}
+
 func TestNoListenAddrs(t *testing.T) {
 	ctx := context.Background()
 	h, err := New(ctx, NoListenAddrs)
Repository: libp2p/go-libp2p
Pull request #988 (2020-08-03 17:43:27)

Bump Autonat version & validate fixed call loop in `.Addrs`


Patch:
diff --git a/go.mod b/go.mod
index bee22b78..a54a412f 100644
--- a/go.mod
+++ b/go.mod
@@ -13,7 +13,7 @@ require (
 	github.com/libp2p/go-addr-util v0.0.2
 	github.com/libp2p/go-conn-security-multistream v0.2.0
 	github.com/libp2p/go-eventbus v0.2.1
-	github.com/libp2p/go-libp2p-autonat v0.3.1
+	github.com/libp2p/go-libp2p-autonat v0.3.2
 	github.com/libp2p/go-libp2p-blankhost v0.2.0
 	github.com/libp2p/go-libp2p-circuit v0.3.1
 	github.com/libp2p/go-libp2p-core v0.6.1
diff --git a/go.sum b/go.sum
index 4da3d888..4e244b4e 100644
--- a/go.sum
+++ b/go.sum
@@ -141,6 +141,8 @@ github.com/libp2p/go-flow-metrics v0.0.3 h1:8tAs/hSdNvUiLgtlSy3mxwxWP4I9y/jlkPFT
 github.com/libp2p/go-flow-metrics v0.0.3/go.mod h1:HeoSNUrOJVK1jEpDqVEiUOIXqhbnS27omG0uWU5slZs=
 github.com/libp2p/go-libp2p-autonat v0.3.1 h1:60sc3NuQz+RxEb4ZVCRp/7uPtD7gnlLcOIKYNulzSIo=
 github.com/libp2p/go-libp2p-autonat v0.3.1/go.mod h1:0OzOi1/cVc7UcxfOddemYD5vzEqi4fwRbnZcJGLi68U=
+github.com/libp2p/go-libp2p-autonat v0.3.2 h1:OhDSwVVaq7liTaRIsFFYvsaPp0pn2yi0WazejZ4DUmo=
+github.com/libp2p/go-libp2p-autonat v0.3.2/go.mod h1:0OzOi1/cVc7UcxfOddemYD5vzEqi4fwRbnZcJGLi68U=
 github.com/libp2p/go-libp2p-blankhost v0.2.0 h1:3EsGAi0CBGcZ33GwRuXEYJLLPoVWyXJ1bcJzAJjINkk=
 github.com/libp2p/go-libp2p-blankhost v0.2.0/go.mod h1:eduNKXGTioTuQAUcZ5epXi9vMl+t4d8ugUBRQ4SqaNQ=
 github.com/libp2p/go-libp2p-circuit v0.3.1 h1:69ENDoGnNN45BNDnBd+8SXSetDuw0eJFcGmOvvtOgBw=


Test patch:
diff --git a/p2p/host/basic/basic_host_test.go b/p2p/host/basic/basic_host_test.go
index f7726da0..2f2ab762 100644
--- a/p2p/host/basic/basic_host_test.go
+++ b/p2p/host/basic/basic_host_test.go
@@ -20,6 +20,7 @@ import (
 	"github.com/libp2p/go-libp2p-core/test"
 
 	"github.com/libp2p/go-eventbus"
+	autonat "github.com/libp2p/go-libp2p-autonat"
 	swarmt "github.com/libp2p/go-libp2p-swarm/testing"
 	"github.com/libp2p/go-libp2p/p2p/protocol/identify"
 
@@ -199,6 +200,16 @@ func TestHostAddrsFactory(t *testing.T) {
 	if !addrs[0].Equal(maddr) {
 		t.Fatalf("expected %s, got %s", maddr.String(), addrs[0].String())
 	}
+
+	var err error
+	h.AutoNat, err = autonat.New(ctx, h, autonat.WithReachability(network.ReachabilityPublic))
+	if err != nil {
+		t.Fatalf("should be able to attach autonat: %v", err)
+	}
+	addrs = h.Addrs()
+	if len(addrs) != 1 {
+		t.Fatalf("didn't expect change in returned addresses.")
+	}
 }
 
 func TestLocalIPChangesWhenListenAddrChanges(t *testing.T) {
Repository: libp2p/go-libp2p
Pull request #1029 (2020-12-08 21:58:40)

fix: obey new stream timeout


Patch:
diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go
index 7338a41e..d69751b0 100644
--- a/p2p/host/basic/basic_host.go
+++ b/p2p/host/basic/basic_host.go
@@ -631,10 +631,24 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I
 		}, nil
 	}
 
-	selected, err := msmux.SelectOneOf(pidStrings, s)
-	if err != nil {
+	// Negotiate the protocol in the background, obeying the context.
+	var selected string
+	errCh := make(chan error, 1)
+	go func() {
+		selected, err = msmux.SelectOneOf(pidStrings, s)
+		errCh <- err
+	}()
+	select {
+	case err = <-errCh:
+		if err != nil {
+			s.Reset()
+			return nil, err
+		}
+	case <-ctx.Done():
 		s.Reset()
-		return nil, err
+		// wait for the negotiation to cancel.
+		<-errCh
+		return nil, ctx.Err()
 	}
 
 	selpid := protocol.ID(selected)


Test patch:
diff --git a/p2p/host/basic/basic_host_test.go b/p2p/host/basic/basic_host_test.go
index 2f2ab762..3585b01b 100644
--- a/p2p/host/basic/basic_host_test.go
+++ b/p2p/host/basic/basic_host_test.go
@@ -3,6 +3,7 @@ package basichost
 import (
 	"bytes"
 	"context"
+	"fmt"
 	"io"
 	"reflect"
 	"sync"
@@ -777,6 +778,49 @@ func TestHostAddrChangeDetection(t *testing.T) {
 	}
 }
 
+func TestNegotiationCancel(t *testing.T) {
+	ctx, cancel := context.WithCancel(context.Background())
+	defer cancel()
+
+	h1, h2 := getHostPair(ctx, t)
+	defer h1.Close()
+	defer h2.Close()
+
+	// pre-negotiation so we can make the negotiation hang.
+	h1.Network().SetStreamHandler(func(s network.Stream) {
+		<-ctx.Done() // wait till the test is done.
+		s.Reset()
+	})
+
+	ctx2, cancel2 := context.WithCancel(ctx)
+	defer cancel2()
+
+	errCh := make(chan error, 1)
+	go func() {
+		s, err := h2.NewStream(ctx2, h1.ID(), "/testing")
+		if s != nil {
+			errCh <- fmt.Errorf("expected to fail negotiation")
+			return
+		}
+		errCh <- err
+	}()
+	select {
+	case err := <-errCh:
+		t.Fatal(err)
+	case <-time.After(10 * time.Millisecond):
+		// ok, hung.
+	}
+	cancel2()
+
+	select {
+	case err := <-errCh:
+		require.Equal(t, err, context.Canceled)
+	case <-time.After(500 * time.Millisecond):
+		// failed to cancel
+		t.Fatal("expected negotiation to be canceled")
+	}
+}
+
 func waitForAddrChangeEvent(ctx context.Context, sub event.Subscription, t *testing.T) event.EvtLocalAddressesUpdated {
 	for {
 		select {
Repository: libp2p/go-libp2p
Pull request #1452 (2022-04-25 15:00:39)

rename the yamux package


Patch:
diff --git a/defaults.go b/defaults.go
index 72ee19cb..7def06f5 100644
--- a/defaults.go
+++ b/defaults.go
@@ -5,7 +5,7 @@ package libp2p
 import (
 	"crypto/rand"
 
-	yamux "github.com/libp2p/go-libp2p/p2p/muxer/yamux"
+	"github.com/libp2p/go-libp2p/p2p/muxer/yamux"
 	"github.com/libp2p/go-libp2p/p2p/net/connmgr"
 	quic "github.com/libp2p/go-libp2p/p2p/transport/quic"
 	"github.com/libp2p/go-libp2p/p2p/transport/tcp"
diff --git a/p2p/muxer/yamux/conn.go b/p2p/muxer/yamux/conn.go
index 5be7ed36..a7c6dc00 100644
--- a/p2p/muxer/yamux/conn.go
+++ b/p2p/muxer/yamux/conn.go
@@ -1,4 +1,4 @@
-package sm_yamux
+package yamux
 
 import (
 	"context"
diff --git a/p2p/muxer/yamux/stream.go b/p2p/muxer/yamux/stream.go
index 1a93916a..f75e77d6 100644
--- a/p2p/muxer/yamux/stream.go
+++ b/p2p/muxer/yamux/stream.go
@@ -1,4 +1,4 @@
-package sm_yamux
+package yamux
 
 import (
 	"time"
diff --git a/p2p/muxer/yamux/transport.go b/p2p/muxer/yamux/transport.go
index ea2cd0e5..0d43208a 100644
--- a/p2p/muxer/yamux/transport.go
+++ b/p2p/muxer/yamux/transport.go
@@ -1,4 +1,4 @@
-package sm_yamux
+package yamux
 
 import (
 	"io/ioutil"


Test patch:
diff --git a/config/muxer_test.go b/config/muxer_test.go
index 96de6e1f..4b00d64c 100644
--- a/config/muxer_test.go
+++ b/config/muxer_test.go
@@ -4,7 +4,7 @@ import (
 	"testing"
 
 	bhost "github.com/libp2p/go-libp2p/p2p/host/basic"
-	yamux "github.com/libp2p/go-libp2p/p2p/muxer/yamux"
+	"github.com/libp2p/go-libp2p/p2p/muxer/yamux"
 	swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
 
 	"github.com/libp2p/go-libp2p-core/host"
diff --git a/p2p/muxer/yamux/transport_test.go b/p2p/muxer/yamux/transport_test.go
index 48136c48..35818966 100644
--- a/p2p/muxer/yamux/transport_test.go
+++ b/p2p/muxer/yamux/transport_test.go
@@ -1,4 +1,4 @@
-package sm_yamux
+package yamux
 
 import (
 	"testing"
diff --git a/p2p/net/swarm/dial_worker_test.go b/p2p/net/swarm/dial_worker_test.go
index b90092c5..a7cc1e8d 100644
--- a/p2p/net/swarm/dial_worker_test.go
+++ b/p2p/net/swarm/dial_worker_test.go
@@ -8,7 +8,7 @@ import (
 	"testing"
 	"time"
 
-	yamux "github.com/libp2p/go-libp2p/p2p/muxer/yamux"
+	"github.com/libp2p/go-libp2p/p2p/muxer/yamux"
 	quic "github.com/libp2p/go-libp2p/p2p/transport/quic"
 	"github.com/libp2p/go-libp2p/p2p/transport/tcp"
 
diff --git a/p2p/net/swarm/testing/testing.go b/p2p/net/swarm/testing/testing.go
index 70359b02..0b75205e 100644
--- a/p2p/net/swarm/testing/testing.go
+++ b/p2p/net/swarm/testing/testing.go
@@ -4,7 +4,7 @@ import (
 	"testing"
 	"time"
 
-	yamux "github.com/libp2p/go-libp2p/p2p/muxer/yamux"
+	"github.com/libp2p/go-libp2p/p2p/muxer/yamux"
 	"github.com/libp2p/go-libp2p/p2p/net/swarm"
 	quic "github.com/libp2p/go-libp2p/p2p/transport/quic"
 	"github.com/libp2p/go-libp2p/p2p/transport/tcp"
Repository: Mogztter/asciidoctor-pdf.js
Pull request #112 (2019-11-12 09:34:40)

adding language support for standard template
The current template has "en" as the only language. This PR uses the `lang` and `nolang` attribute to determine the HTML lang attribute like the html5.rb in Asciidoctor.

I placed the test cases quite at the top as the `<html>` is also at the top of the created file.


Patch:
diff --git a/lib/document/templates.js b/lib/document/templates.js
index ddd9944..29431e4 100644
--- a/lib/document/templates.js
+++ b/lib/document/templates.js
@@ -145,6 +145,15 @@ const assetUriScheme = (node) => {
   return result
 }
 
+const langAttr = (node) => {
+  const attrNolang = node.getAttribute('nolang')
+  if (attrNolang === '') {
+    return ''
+  }
+  const attrLang = node.getAttribute('lang','en')
+  return ` lang="${attrLang}"`
+}
+
 const isSvgIconEnabled = (node) => node.getDocument().isAttribute('icontype', 'svg') || node.getDocument().isAttribute('icons', 'font')
 
 const titlePage = (node) => {
@@ -211,7 +220,7 @@ ${node.getContent()}
       bodyAttrs.push(`style="max-width: ${node.getAttribute('max-width')};"`)
     }
     return `<!DOCTYPE html>
-<html dir="ltr" lang="en">
+<html dir="ltr"${langAttr(node)}>
 <head>
 <title>${node.getDocumentTitle({ sanitize: true, use_fallback: true })}</title>
 <meta charset="UTF-8">


Test patch:
diff --git a/test/templates_test.js b/test/templates_test.js
index a832f03..ae7453c 100644
--- a/test/templates_test.js
+++ b/test/templates_test.js
@@ -12,6 +12,34 @@ const templates = require('../lib/document/templates.js')
 converter.registerTemplateConverter(asciidoctor, templates)
 
 describe('Default converter', () => {
+  describe('Language', () => {
+    it('should have a default language', () => {
+      const doc = asciidoctor.load(`= Title
+
+== Section`)
+      const $ = cheerio.load(templates.document(doc))
+      expect($('html').attr('lang')).to.equal('en')
+    })
+
+    it('respect the document lang attribute', () => {
+      const doc = asciidoctor.load(`= Title
+:lang: de
+
+== Section`)
+      const $ = cheerio.load(templates.document(doc))
+      expect($('html').attr('lang')).to.equal('de')
+    })
+
+    it('respect the document nolang attribute', () => {
+      const doc = asciidoctor.load(`= Title
+:nolang:
+
+== Section`)
+      const $ = cheerio.load(templates.document(doc))
+      expect($('html').attr('lang')).to.be.undefined()
+    })
+  })
+
   describe('Page title', () => {
     it('should include a title page if title-page attribute is defined', () => {
       const doc = asciidoctor.load(`= Title
Repository: vuejs/composition-api
Pull request #618 (2020-12-27 06:39:56)

refactor: remove expressions that is always false
`shallowReactive` and `shallowReadonly` have only one argument, so `arguments.length === 2` is always `false`.


Patch:
diff --git a/src/apis/useCssModule.ts b/src/apis/useCssModule.ts
index 368abd7..335c3d2 100644
--- a/src/apis/useCssModule.ts
+++ b/src/apis/useCssModule.ts
@@ -12,7 +12,7 @@ export const useCSSModule = (name = '$style'): Record<string, string> => {
     return EMPTY_OBJ
   }
 
-  const mod = (instance as any)[name]
+  const mod = (instance.proxy as any)?.[name]
   if (!mod) {
     __DEV__ &&
       warn(`Current instance does not have CSS module named "${name}".`)
diff --git a/src/reactivity/reactive.ts b/src/reactivity/reactive.ts
index 9414051..6cdaa82 100644
--- a/src/reactivity/reactive.ts
+++ b/src/reactivity/reactive.ts
@@ -162,12 +162,6 @@ export function shallowReactive(obj: any): any {
       }
       getter = property.get
       setter = property.set
-      if (
-        (!getter || setter) /* not only have getter */ &&
-        arguments.length === 2
-      ) {
-        val = obj[key]
-      }
     }
 
     Object.defineProperty(observed, key, {
diff --git a/src/reactivity/readonly.ts b/src/reactivity/readonly.ts
index 10ca241..c4e3445 100644
--- a/src/reactivity/readonly.ts
+++ b/src/reactivity/readonly.ts
@@ -59,20 +59,12 @@ export function shallowReadonly(obj: any): any {
   for (const key of Object.keys(obj)) {
     let val = obj[key]
     let getter: (() => any) | undefined
-    let setter: ((x: any) => void) | undefined
     const property = Object.getOwnPropertyDescriptor(obj, key)
     if (property) {
       if (property.configurable === false) {
         continue
       }
       getter = property.get
-      setter = property.set
-      if (
-        (!getter || setter) /* not only have getter */ &&
-        arguments.length === 2
-      ) {
-        val = obj[key]
-      }
     }
 
     Object.defineProperty(readonlyObj, key, {


Test patch:
diff --git a/test/apis/useCssModule.spec.js b/test/apis/useCssModule.spec.js
new file mode 100644
index 0000000..63c40a8
--- /dev/null
+++ b/test/apis/useCssModule.spec.js
@@ -0,0 +1,31 @@
+const Vue = require('vue/dist/vue.common.js')
+const { useCSSModule } = require('../../src')
+
+const style = { whateverStyle: 'whateverStyle' }
+
+function injectStyles() {
+  Object.defineProperty(this, '$style', {
+    configurable: true,
+    get: function () {
+      return style
+    },
+  })
+}
+
+describe('api/useCssModule', () => {
+  it('should get the same object', (done) => {
+    const vm = new Vue({
+      beforeCreate() {
+        injectStyles.call(this)
+      },
+      template: '<div>{{style}}</div>',
+      setup() {
+        const style = useCSSModule()
+        return { style }
+      },
+    })
+    vm.$mount()
+    expect(vm.style).toBe(style)
+    done()
+  })
+})
Repository: vuejs/composition-api
Pull request #624 (2021-01-06 09:45:27)

fix(getCurrentInstance): emit event
`getCurrentInstance().emit` is not working

also typo on `getCurrentVu2Instance`


Patch:
diff --git a/src/runtimeContext.ts b/src/runtimeContext.ts
index 557dfe9..81089ad 100644
--- a/src/runtimeContext.ts
+++ b/src/runtimeContext.ts
@@ -145,7 +145,7 @@ export declare interface ComponentInternalInstance {
   isDeactivated: boolean
 }
 
-export function getCurrentVu2Instance() {
+export function getCurrentVue2Instance() {
   return currentInstance
 }
 
@@ -173,6 +173,9 @@ function toVue3ComponentInstance(
     update: vue2Instance.$forceUpdate,
     uid: vue2Instance._uid,
 
+    // $emit is defined on prototype and it expected to be bound
+    emit: vue2Instance.$emit.bind(vue2Instance),
+
     parent: null,
     root: null as any,
   } as unknown) as ComponentInternalInstance
@@ -183,7 +186,6 @@ function toVue3ComponentInstance(
     'props',
     'attrs',
     'refs',
-    'emit',
     'vnode',
     'slots',
   ] as const
diff --git a/src/utils/instance.ts b/src/utils/instance.ts
index e2d242d..3ee24ed 100644
--- a/src/utils/instance.ts
+++ b/src/utils/instance.ts
@@ -1,6 +1,6 @@
 import { ComponentInstance } from '../component'
 import vmStateManager from './vmStateManager'
-import { setCurrentInstance, getCurrentVu2Instance } from '../runtimeContext'
+import { setCurrentInstance, getCurrentVue2Instance } from '../runtimeContext'
 import { Ref, isRef } from '../apis'
 import { hasOwn, proxy, warn } from './utils'
 import { createSlotProxy, resolveSlots } from './helper'
@@ -112,7 +112,7 @@ export function activateCurrentInstance(
   fn: (vm_: ComponentInstance) => any,
   onError?: (err: Error) => void
 ) {
-  let preVm = getCurrentVu2Instance()
+  let preVm = getCurrentVue2Instance()
   setCurrentInstance(vm)
   try {
     return fn(vm)


Test patch:
diff --git a/test/v3/runtime-core/componentProxy.spec.ts b/test/v3/runtime-core/componentProxy.spec.ts
index a05d82b..08cf18f 100644
--- a/test/v3/runtime-core/componentProxy.spec.ts
+++ b/test/v3/runtime-core/componentProxy.spec.ts
@@ -45,7 +45,12 @@ describe('component: proxy', () => {
       components: {
         Comp,
       },
-      template: '<Comp/>',
+      data() {
+        return {
+          update: 0,
+        }
+      },
+      template: '<Comp @update="update++"/>',
     }
     const app = createApp(Parent).mount(document.createElement('div'))
 
@@ -60,10 +65,17 @@ describe('component: proxy', () => {
       instance!.parent && instance!.parent.proxy
     )
     expect(instanceProxy.$root).toBe(instance!.root.proxy)
-    expect(instanceProxy.$emit).toBe(instance!.emit)
     expect(instance.isMounted).toBe(true)
     expect(instance.isUnmounted).toBe(false)
 
+    // @ts-expect-error no typings
+    expect(app.update).toBe(0)
+
+    instance!.emit('update')
+
+    // @ts-expect-error no typings
+    expect(app.update).toBe(1)
+
     // expect(instanceProxy.$el).toBe(instance!.vnode.el)
     // expect(instanceProxy.$options).toBe(instance!.type)
Repository: vuejs/composition-api
Pull request #638 (2021-01-26 06:39:34)

test: add failed test for #498


Patch:
diff --git a/src/reactivity/reactive.ts b/src/reactivity/reactive.ts
index 7599ab6..d08b7c5 100644
--- a/src/reactivity/reactive.ts
+++ b/src/reactivity/reactive.ts
@@ -94,14 +94,14 @@ export function defineAccessControl(target: AnyObject, key: any, val?: any) {
     set: function setterHandler(newVal: any) {
       if (getter && !setter) return
 
-      const value = getter ? getter.call(target) : val
       // If the key is equal to RefKey, skip the unwrap logic
       // If and only if "value" is ref and "newVal" is not a ref,
       // the assignment should be proxied to "value" ref.
-      if (key !== RefKey && isRef(value) && !isRef(newVal)) {
-        value.value = newVal
+      if (key !== RefKey && isRef(val) && !isRef(newVal)) {
+        val.value = newVal
       } else if (setter) {
         setter.call(target, newVal)
+        val = newVal
       } else {
         val = newVal
       }


Test patch:
diff --git a/test/v3/runtime-core/apiWatch.spec.ts b/test/v3/runtime-core/apiWatch.spec.ts
index 6fde5b2..d1f440a 100644
--- a/test/v3/runtime-core/apiWatch.spec.ts
+++ b/test/v3/runtime-core/apiWatch.spec.ts
@@ -532,6 +532,28 @@ describe('api: watch', () => {
     expect(data2.value).toMatchObject([1])
   })
 
+  // #498
+  it('watchEffect should not lead to infinite loop when accessing', async () => {
+    let dummy = 0
+
+    const state = reactive({
+      data: [],
+      watchVar: 123,
+    })
+
+    watchEffect(() => {
+      // accessing
+      state.watchVar
+      // setting
+      state.data = []
+      dummy += 1
+    })
+
+    expect(dummy).toBe(1)
+    await nextTick()
+    expect(dummy).toBe(1)
+  })
+
   it('watching deep ref', async () => {
     const count = ref(0)
     const double = computed(() => count.value * 2)