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

Consider dropping Oxygen.env and use process.env instead #1226

Closed
jplhomer opened this issue May 6, 2022 · 5 comments · May be fixed by #1314
Closed

Consider dropping Oxygen.env and use process.env instead #1226

jplhomer opened this issue May 6, 2022 · 5 comments · May be fixed by #1314
Assignees
Labels
framework Related to framework aspects of Hydrogen

Comments

@jplhomer
Copy link
Contributor

jplhomer commented May 6, 2022

In #55, we decided to introduce first-class Oxygen.env support for Hydrogen. This was designed around the intent that Oxygen would inject this in its Web runtime.

However, we've since pivoted away from that plan, and Oxygen is no longer going to do that. This means Hydrogen is responsible for injecting this variable on its own.

This is confusing for a number of reasons, primarily because it means Hydrogen builds a unique affordance for runtime environment variables that doesn't exist on any platform — literally.

Meanwhile, Vite now supports process.env in SSR runtimes (it previously did not).

I propose that we adopt process.env for runtime environment variables in Hydrogen.

This means populating a process.env in our platforms/worker.ts file. It also means updating all instances of Oxygen.env with process.env.

I think this better matches the behavior in other frameworks deployed to Workers runtimes as well.

Drawbacks

  • Does the presence of process trick any 3p libs into thinking we are running in Node, thus causing compatibility issues?
  • Is it going to be confusing that other process properties are not available?
@jplhomer jplhomer added the framework Related to framework aspects of Hydrogen label May 6, 2022
@wizardlyhel
Copy link
Collaborator

wizardlyhel commented May 6, 2022

Would it in conflict with this?

https://github.com/Shopify/hydrogen/blob/v1.x-2022-07/packages/hydrogen/src/streaming.server.ts#L44-L46

export async function isStreamingSupported() {
  return Boolean(globalThis.Oxygen?.env?.HYDROGEN_ENABLE_WORKER_STREAMING);
}

which is currently preventing streaming from happening on any platform that is not Oxygen.

@jplhomer
Copy link
Contributor Author

jplhomer commented May 6, 2022

(I think we can remove that — checking to see if streaming is supported natively right now)

We also consider a Node.js streamable by default.

@davidhousedev
Copy link

Love this idea! Something else to consider: many packages key off 'process.env.NODE_ENV === "development"' in order to expose local dev warnings. If NODE_ENV is not set, you may even run into !== "production" checks which could leak dev warnings in prod environments.

Might there be other NODE_ENV vars that represent system architecture attributes where you could differentiate?

How does Cloudflare handle this in workers? Have they encountered any issues with library compat?

@benjaminsehl
Copy link
Member

Now tracking in #1879

@frehner
Copy link
Contributor

frehner commented Oct 5, 2022

Duplicate of #1879

@frehner frehner marked this as a duplicate of #1879 Oct 5, 2022
@frehner frehner closed this as completed Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework Related to framework aspects of Hydrogen
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants