Skip to content

fix: avoid double encoding when notifying dev server of activity #7300

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

Merged
merged 1 commit into from
May 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/utils/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ const serveRedirect = async function ({
(await isEndpointExists(decodeURIComponent(reqUrl.pathname), options.target))
if (staticFile || endpointExists) {
const pathname = staticFile || reqUrl.pathname
req.url = encodeURI(pathname) + reqUrl.search
req.url = encodeURI(decodeURI(pathname)) + reqUrl.search
Copy link
Member

Choose a reason for hiding this comment

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

why decodeURIComponent on line 365 and decodeURI here? can we use the same one and share the result?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's iterate on this, I need this released faster, and this micro optimization not worth the additional testing effort

// if there is an existing static file and it is not a forced redirect, return the file
if (!match.force) {
return proxy.web(req, res, { ...options, staticFile })
Expand Down Expand Up @@ -858,7 +858,17 @@ const onRequest = async (
},
}

const maybeNotifyActivity = () => {
if (req.method === 'GET' && api && process.env.NETLIFY_DEV_SERVER_ID) {
notifyActivity(api, siteInfo.id, process.env.NETLIFY_DEV_SERVER_ID)
}
}

if (match) {
if (!isExternal(match)) {
maybeNotifyActivity()
}

// We don't want to generate an ETag for 3xx redirects.
// @ts-expect-error TS(7031) FIXME: Binding element 'statusCode' implicitly has an 'an... Remove this comment to see the full error message
req[shouldGenerateETag] = ({ statusCode }) => statusCode < 300 || statusCode >= 400
Expand Down Expand Up @@ -886,9 +896,7 @@ const onRequest = async (
return proxy.web(req, res, { target: functionsServer })
}

if (req.method === 'GET' && api && process.env.NETLIFY_DEV_SERVER_ID) {
notifyActivity(api, siteInfo.id, process.env.NETLIFY_DEV_SERVER_ID)
}
maybeNotifyActivity()

proxy.web(req, res, options)
}
Expand Down
Loading