Skip to content

Conversation

@razor-x
Copy link
Member

@razor-x razor-x commented May 27, 2023

  • refactor: Prefer disabled over enabled
  • refactor: Return early from effect
  • docs: Import CSS in example
  • feat: Add useUnminifiedCss prop
  • fix: Use correct version for stylesheet

endpoint={import.meta.env.SEAM_ENDPOINT}
publishableKey={import.meta.env.SEAM_PUBLISHABLE_KEY}
userIdentifierKey={import.meta.env.SEAM_USER_IDENTIFIER_KEY}
disableCssInjection
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to put this in the example since when running locally the example should use the latest styles. We can keep the font injection.

"lint": "eslint --ignore-path .gitignore --ext .js,.cjs,.mjs,.ts,.tsx .",
"prelint": "prettier --check --ignore-path .gitignore .",
"postlint": "stylelint '**/*.scss'",
"prepack": "echo \"export default '$(jq -r .version < package.json)'\" > lib/version.js",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally I would like to use a platform independent script (can always be done later), but this will ONLY run on CI so it should be safe to do this for now.


export const useSeamStyles = ({ enabled }: { enabled: boolean }) => {
useEffect(() => {
if (version === null) return
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In development the version will always be null.

@razor-x razor-x marked this pull request as ready for review May 27, 2023 01:29
@razor-x razor-x requested a review from azat-co as a code owner May 27, 2023 01:29
@razor-x razor-x requested a review from seveibar May 27, 2023 01:29
@razor-x razor-x changed the title Use correct CSS version Use correct CSS version when injecting link tag May 27, 2023
@razor-x
Copy link
Member Author

razor-x commented May 27, 2023

UI test for the supported device table is flaky, seems it get stuck loading sometimes.

@razor-x razor-x requested a review from mikewuu May 27, 2023 01:39
Copy link
Contributor

@seveibar seveibar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw i was testing this w/ yalc to make sure the imports go through properly, it's a bit hard to test, maybe you know a better way

const cssUrl = 'https://www.unpkg.com/@seamapi/react@1.1.0/index.min.css'
import version from 'lib/version.js'

const origin = 'https://react.seam.co'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we always use the css file in the release / bundle, wouldn't it always have the correct version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because we are injecting a URL that contains the version number which must match the version of the package that is being used by the user. I'm not sure if that explanation is more clear, but it's correct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because we are injecting a URL that contains the version number

Yep, was wondering what the benefits of injecting via URL vs. just including what is bundled with the package are?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, there is a pretty long internal discussion about this. The short version is that having it inject the fonts and the styles simplifies adoption and removes all the extra steps you need to use this.

It's still possible to opt out of the HTML injection and do it the other way for users who prefer that.

Copy link
Contributor

@mikewuu mikewuu May 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was actually thinking of dynamically importing the css via relative paths, but of course that wouldn't work because this is runtime.

What if we always include the CSS, but just change the class name? Won't have to deal with version numbers, and no dynamic loading necessary?

Root component / provider

const class = disableStyles ? '' : 'seam-components'

return (<div className={class}>...</div>)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we always include the CSS

I'm not sure I understand this. With this update we are always including the css unless the user opts out. I'd prefer not to inject the via an inline style tag since that bloats the js bundle size and cannot take advantage of caching the same way (among other things).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to inject the via an inline style tag

Yep, I mean we'd be able to avoid that. Here's a PR:

#191

@razor-x
Copy link
Member Author

razor-x commented May 27, 2023

fwiw i was testing this w/ yalc to make sure the imports go through properly, it's a bit hard to test, maybe you know a better way

@seveibar It's a little difficult to test things that only happen in the built package (very few things that hit that edge case). It's possible though: the install CI action actually ensures the package will be installable and the all it's modules will resolve.

This case it pretty special though. We could add an example app that ONLY uses the deployed version (would not "sync" with local dev). That would give a way to test it (I basically did that locally to verify this will work).

@razor-x
Copy link
Member Author

razor-x commented May 27, 2023

@seveibar #189

@razor-x razor-x merged commit 53f8c7e into main May 27, 2023
@razor-x razor-x deleted the css-version branch May 27, 2023 02:02
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 this pull request may close these issues.

3 participants