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

Unexpected Syntax on Old Browser #331

Open
PutawanDE opened this issue Jul 17, 2024 · 3 comments
Open

Unexpected Syntax on Old Browser #331

PutawanDE opened this issue Jul 17, 2024 · 3 comments

Comments

@PutawanDE
Copy link

I got SyntaxError: expected expression, got '?' reported to Sentry on my application. I noticed that it was from

(window[Symbol.for("ApolloSSRDataTransport")
] ??= []).push({
        "json": ......

This part was injected to HTML document of my website. Syntax ??= is not supported on my user's browser. I found that transportDataToJS function in dataTransport.ts return string of js containing this syntax.

So, what's the impact if this code doesn't work on the browser? And can we rewrite this using the older syntax?

@phryneas
Copy link
Member

How old are we talking here?

By my knowledge, there is no browser version out there that is still receiving security updates or any other kind of vendor support that doesn't support this syntax:

@PutawanDE
Copy link
Author

Chrome version 67. Yes it is old. So I use a transpiler but the transpiler cannot transpile this because syntax ??= is in a string that is sent to client. Can I know how to deal with this issue? Thank you.
image

@phryneas
Copy link
Member

phryneas commented Jul 19, 2024

I would probably suggest something like patch-package to replace this code with something like

  return `{let k=Symbol.for("${key}"),w=window;(w[k]=w[k]||[]).push(${htmlEscapeJsonString(
    stringify(data)
  )})}`;

I'm not convinced that we want to upstream that into the library itself though, since this code is injected into the webpage a lot and we want to save transferred data overall.

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

No branches or pull requests

2 participants