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

Support remove default style on client side #713

Closed
1 of 2 tasks
Jokcy opened this issue Feb 12, 2023 · 2 comments · Fixed by #787
Closed
1 of 2 tasks

Support remove default style on client side #713

Jokcy opened this issue Feb 12, 2023 · 2 comments · Fixed by #787
Labels
triage New issues that needs consideration

Comments

@Jokcy
Copy link
Contributor

Jokcy commented Feb 12, 2023

Tell us how you think we can improve Sandpack

Currently sandpack provided a SANDPACK_BARE_COMPONENTS env variable to remove default style generated by stitches, but the syntax seems not work in most cases.

const getNodeProcess = (): false | string | undefined => {
  if (typeof process !== "undefined") {
    return process.env.SANDPACK_BARE_COMPONENTS;
  }

  return false;
};

for most client cases typeof process will be undefined because build tools like webpack will directly replace process.env.xxx instead of expose a process object to global. So this will always not work on client side.

Besides the name of the function getNodeProcess seems designed for only work on node process?

Packages affected

  • sandpack-client
  • sandpack-react

What is this feature?

Support remove default style on client side.

How would your idea work?

Just use

const getNodeProcess = (): false | string | undefined => {
    return process.env.SANDPACK_BARE_COMPONENTS;
};

And in case to support some meta framework like next, maybe we can use:

const getNodeProcess = (): false | string | undefined => {
    return process.env.SANDPACK_BARE_COMPONENTS || process.env.NEXT_PUBLIC_SANDPACK_BARE_COMPONENTS  ;
};

Do you have any examples of how you would like to see us implement it?

const getNodeProcess = (): false | string | undefined => {
    return process.env.SANDPACK_BARE_COMPONENTS || process.env.NEXT_PUBLIC_SANDPACK_BARE_COMPONENTS  ;
};
@Jokcy Jokcy added feature:request triage New issues that needs consideration labels Feb 12, 2023
@Jokcy
Copy link
Contributor Author

Jokcy commented Feb 28, 2023

This env variable should work at build time so it should be fine with Nextjs🤔, but if I disable SSR for some page it still not work. Need to look deep to find the reason.

@Jokcy
Copy link
Contributor Author

Jokcy commented Mar 1, 2023

https://codesandbox.io/p/sandbox/amazing-hooks-qui6b8?file=%2Fpages%2Findex.tsx&selection=%5B%7B%22endColumn%22%3A49%2C%22endLineNumber%22%3A30%2C%22startColumn%22%3A49%2C%22startLineNumber%22%3A30%7D%5D

As this demo shows, nextjs will build code into to version, one for client side and one for server side, the server side build work fine with the env variable but the client build not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New issues that needs consideration
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant