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

user-agent header always the same in cloudflare pages #4668

Closed
simcolin opened this issue Apr 20, 2022 · 8 comments · Fixed by #4669
Closed

user-agent header always the same in cloudflare pages #4668

simcolin opened this issue Apr 20, 2022 · 8 comments · Fixed by #4669

Comments

@simcolin
Copy link

Describe the bug

When deploying to cloudflare pages, the "user-agent" header in the Handle Hook seems to always have the same value.

It works as expected while running in dev or preview in local.
It tried disabling prerendering and disabling ssr but it changes nothing.

I don't even know if the problem is comming from the cloudflare adapter, cloudflare itself, or sveltekit

Reproduction

hooks.ts

export const handle = async ({ event, resolve }) => {
    if (event.request.headers.has("user-agent")) {
        event.locals.userAgent = event.request.headers.get("user-agent");
    }
    return await resolve(event);
};

export const getSession = (event) => {
    return event.locals;
}

index.svelte

<script>
    import { session } from "$app/stores";
</script>

{$session.userAgent}

Deploy to cloudflare pages

It setted up a pages just to test this behaviour if you want to see the result for yourself : https://test-bug-cloudflare.pages.dev/
No matter the device, the same text is printed.

Logs

No response

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
    Memory: 20.25 GB / 31.93 GB
  Binaries:
    Node: 16.14.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.5.3 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (98.0.1108.43)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.34
    @sveltejs/kit: next => 1.0.0-next.316
    svelte: ^3.47.0 => 3.47.0

Severity

serious, but I can work around it

Additional Information

No response

@PH4NTOMiki
Copy link
Contributor

For me the demo, it's showing the right result.

@PH4NTOMiki
Copy link
Contributor

Actually that was the first time, second time(after I changed it) it was the same as the first time. And the CF cache header is HIT, so for some reason it gets cached.

@simcolin
Copy link
Author

Isn't that weird that Cloudflare caches the page for different devices ? Seems it's cached even for different IPs : I have the same result on my phone with 4G.

@PH4NTOMiki
Copy link
Contributor

It's per region (colocation) only, probably

@PH4NTOMiki
Copy link
Contributor

But I'm not sure how you turned it on, because it's not in your code

@PH4NTOMiki
Copy link
Contributor

It should somewhere in their panel

@simcolin
Copy link
Author

I didn't turned anything on, I tested on a fresh project, so it must be on by default. The Cloudflare Pages panel is quite small and doesn't seem to grant control over caching.

The problem is not related to sveltekit so I will close the issue. @PH4NTOMiki thank you for pointing out where the problem was.

@PH4NTOMiki
Copy link
Contributor

No problem, cc @lukeed maybe he can help you

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 a pull request may close this issue.

2 participants