getPersonalizedURL not compatible with NextJS v13
Describe the bug
When running NextJS v13, getPersonalizedURL causes a request.cookies.entries is not a function error.
getPersonalizedURL relies on the NextRequest, which has changed in NextJS 13. Cookies now have a name and a value prop, and there is no longer request.cookies.entries.
To Reproduce
Steps to reproduce the behavior:
- On an application running NextJS v13, run middleware using
getPersonalizedURLfollowing instruction in the documentation.
Expected behavior A personalized URL should be generated.
Additional context
Replacing
const allCookies = Array.from(request.cookies.entries()).reduce(
(acc, [key]) => ({
...acc,
[key]: tryJsonParse(request.cookies.get(key)!),
}),
{}
);
with
const allCookies: Record<string, any> = {};
for (const cookie of request.cookies) {
const key = cookie[0];
const value = request.cookies.get(key)?.value;
if (value) {
const parsedCookie = tryJsonParse(value);
allCookies[key] = parsedCookie;
}
}
appears to solve the issue for us.
@Ross-s can you please release this change in an updated NPM package? 2.0.0 on NPM still refers to the .entries() syntax (https://www.npmjs.com/package/@builder.io/personalization-utils?activeTab=code)
@Ross-s can you please release this change in an updated NPM package? 2.0.0 on NPM still refers to the .entries() syntax (https://www.npmjs.com/package/@builder.io/personalization-utils?activeTab=code)
@teleaziz