phryneas / ssr-only-secrets

This package provides a way to pass secrets from Server Components into the SSR-run of Client Components, without them being accessible in the browser.
https://www.npmjs.com/package/ssr-only-secrets
MIT License
20 stars 1 forks source link

Small tweaks to work on Edge Runtime #2

Open pugbyte opened 5 months ago

pugbyte commented 5 months ago

Hi there, I just started using this package and it's been pretty great so far. One small issue I noticed was that there were some hiccups when I tried to use it on Next.js with the Edge Runtime option turned on.

  1. This package internally uses experimental_taintUniqueValue from React, which needs to be enabled by a config option in next.config.js. Oddly, needing the config is only an issue when using the edge runtime, not the nodejs runtime. I think it's worth mentioning the use of experimental_taintUniqueValue in the project README so users can be aware of this.
  2. The package.json doesn't have a specific exports key for the Edge Runtime, so it just uses the default which is the browser one. This results in being unable to use readSSROnlySecret() on the Edge Runtime since the version exported for browser just returns undefined. If you add export keys like this: "edge-light": "./dist/ssr.js" to the package.json of this project, that will fix it. I tried that with yarn patch and it worked for me.

Let me know if there's any other information I can provide.

phryneas commented 5 months ago

Hi there! I'm in the middle of moving houses right now, so I'll probably need some time to come back to this. Could you please give me a ping on this issues in two weeks of time or so? I just don't have any spare time right now.

I'm sorry for the inconvenience!

pugbyte commented 5 months ago

No worries at all, good luck with the move. I could make a PR if it's any help to you.