question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

clone twice works incorrect in v3.1.0

See original GitHub issue

Call response.clone() twice cause issue in v3.1.0, in v3.0.0 it works as expected

await res.clone().text(); // here it will return the same text as res contains
await res.clone().text(); // here it will return empty

Problem I think in change that was done in clone method, it reads body from instance[INTERNALS] let {body} = instance[INTERNALS];, but then updates different property stream instance[INTERNALS].stream = p1; and body remains the same. But in v3.0.0 it both reads and then updates [INTERNALS].body

Reproduction

Steps to reproduce the behavior:

test:

it('should support clone() method', async () => {
	const body = stream.Readable.from('a=1');
	const res = new Response(body, {
		headers: {
			a: '1'
		},
		url: base,
		status: 346,
		statusText: 'production',
		highWaterMark: 789
	});
	const cl = res.clone();
	expect(cl.headers.get('a')).to.equal('1');
	expect(cl.type).to.equal('default');
	expect(cl.url).to.equal(base);
	expect(cl.status).to.equal(346);
	expect(cl.statusText).to.equal('production');
	expect(cl.highWaterMark).to.equal(789);
	expect(cl.ok).to.be.false;
	// Clone body shouldn't be the same body
	expect(cl.body).to.not.equal(body);

	await cl.text().then(result => {
		expect(result).to.equal('a=1');
	})

	const cl2 = res.clone();

	await cl2.text().then(result => {
		expect(result).to.equal('a=1');
	});
});

Fails in last expect, result is empty instead of a=1

Expected behavior

Test passed

Your Environment

software version
node-fetch 3.1.0
node 12.22.7
npm 6.x
Operating System mac os

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
jimmywartingcommented, Jan 27, 2022

hopefully going to take a closer look to this tonight.

0reactions
chadkirbycommented, Aug 4, 2022

This bug is still present in v3.2.10.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The remote end hung up unexpectedly while git cloning
Quick solution: With this kind of error, I usually start by raising the postBuffer size by: git config --global http.postBuffer 524288000.
Read more >
Does git clone overwrite the existing files in the directory is ...
But no, clone even refuses to clone into an existing empty directory.
Read more >
95 questions with answers in TA CLONING | Scientific method
Hi all, These days, I tried to move an insert originally in the TA cloning vector (pGEM-T Easy, Promega) to my target plasmid...
Read more >
Fixed issues in Illustrator releases - Adobe Support
We've been working hard at fixing the issues you reported to us. Here's a list of issues we fixed in the latest release...
Read more >
Internet Explorer (IE) mode troubleshooting and FAQ
Incorrect Document mode configurations; Incomplete neutral site ... For example, buttons that worked with Internet Explorer don't do ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found