Skip to content
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

avoid re-instantiating Response when not required #902

Conversation

sassanh
Copy link

@sassanh sassanh commented Nov 2, 2024

The problem is described here: #894
You may ignore the rest and just read the last comment

Copy link

changeset-bot bot commented Nov 2, 2024

⚠️ No Changeset found

Latest commit: 960dc6a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sassanh sassanh marked this pull request as draft November 2, 2024 22:36
@sassanh sassanh force-pushed the avoid-re-instantiating-response-when-not-needed branch from ab0c9a9 to 960dc6a Compare November 2, 2024 23:34
@sassanh sassanh marked this pull request as ready for review November 2, 2024 23:35
@@ -131,7 +131,7 @@ export async function runOrFetchBuildOutputItem(
return new Response('Internal Server Error', { status: 500 });
}

return createMutableResponse(resp);
return resp;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generateResponse uses this function, but it already does what createMutableResponse does when needed.

It is also used here packages/next-on-pages/templates/_worker.js/routes-matcher.ts:239, but since my app is not using middlewares I couldn't test it, npm run test:unit passes though.
If it is needed there, maybe we can do createMutableResponse locally for it?

Hopefully my changes are not fundamentally against your design, I just went with common sense based on my very limited knowledge on the codebase.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to

	if (resp.status === 101) {
		return resp;
	}
	return createMutableResponse(resp);

again this is an attempt to allow websocket connections without knowing much about the codebase, I don't know if it is only status code 101 we should put this exception for, or if it is the correct signal for the exception.

@sassanh
Copy link
Author

sassanh commented Nov 11, 2024

It is going to be resolved in workerd as mentioned here

@sassanh sassanh closed this Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant