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

add fix for pseudo elements #48

Merged
merged 7 commits into from
Dec 3, 2018

Conversation

hipstersmoothie
Copy link
Contributor

html-sketchapp doesn't support pseudo elements html-sketchapp/html-sketchapp#20.

A fix for this is proposed by html-sketchapp/html-sketchapp#20 (comment) but the maintainer doesn't want to add it due to it not covering all cases.

I think this would be a good place for the code to live though. I have test it with the icon font that my app uses and it works pretty well. Definitely better than not rendering at all.

Currently it runs by default for every page. This behavior could be guarded by a flag though. I am willing to add this if you want @chrisvxd. Are you open to adding this?

@chrisvxd
Copy link
Owner

chrisvxd commented Nov 18, 2018 via email

@hipstersmoothie
Copy link
Contributor Author

@chrisvxd any chance you could get to this soon?

Copy link
Owner

@chrisvxd chrisvxd left a comment

Choose a reason for hiding this comment

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

Yup, sorry about the delay. Busy time of year.

First off, thanks for the contribution! 👏

I've spoken to the Konrad from the html-sketchapp team about this PR, and I think despite it not being supported upstream, I'm happy to bring it in (along with other tricks like it) until they are supported properly upstream.

My review:

1. Error

I've not been able to get this working as the code seems to throw an error when I run it against the official storybook example:

yarn compile
./lib/server/index.js --verbose --output test.asketch.json --concurrency 4 --url https://storybooks-official.netlify.com/iframe.html

Produces the error:

Error: Evaluation failed: TypeError: allElements[i].className.replace is not a function
    at fixPseudoElements (/Users/chrisvilla/Projects/story2sketch/lib/server/../browser/page2layers.bundle.js:2069:59)
    at Object.getSymbol (/Users/chrisvilla/Projects/story2sketch/lib/server/../browser/page2layers.bundle.js:2119:3)
    at <anonymous>:4:12
    at ExecutionContext.evaluateHandle (/Users/chrisvilla/Projects/story2sketch/node_modules/puppeteer/lib/ExecutionContext.js:58:15)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)

Along with a load of other errors because the page is no longer defined (that's a problem on my side, not yours, see #51).

This occurs when testing against my chris/add-examples branch example too. Master runs cleanly against both of these (although fails to produce output on the official storybook example).

2. Tests

This is a more significant problem than this PR, but story2sketch really needs tests (#52). I feel a bit nervous about letting in something that actually modifies the DOM into story2sketch without test coverage, but unfortunately I'm pretty time constrained and haven't had the time to set up the testing for this project. If I do merge this as-is, I might be tempted to hold off doing a release until some test coverage is added to story2sketch.

3. Format

Please execute prettier on the code - I need to add some linting (and will do so as part of #52).

@hipstersmoothie
Copy link
Contributor Author

hipstersmoothie commented Dec 3, 2018

@chrisvxd

  1. Fixed this. This was an issue where SVG elements dont actually use a string for the className (The script passed but i could not open it in sketch, although i could no open it on master either)
  2. I have hidden this code behind the --fixPseudo flag. This behavior shouldn't effect regular users and is opt in. This should mitigate the risk quite a bit
  3. Done!

Copy link
Owner

@chrisvxd chrisvxd left a comment

Choose a reason for hiding this comment

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

Great idea re the flag! Have managed to test this and it's working as expected.

One small typo and will merge 😎

README.md Outdated
| viewports | Viewport configuration. Will be arranged left-to-right by width. Try to avoid changing the key, as this is used to identify the symbol. | object | Mobile viewport (320px wide) and desktop viewport (1920px wide). See example below. |
| querySelector | Query selector to select your node on each page. Uses `document.querySelectorAll`. | string | `"#root"` |
| verbose | Verbose logging output. | boolean | `false` |
| fixPseudo | Attempt to insert real elements in place of pseudo-elemenets | boolean | `false` |
Copy link
Owner

Choose a reason for hiding this comment

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

I love it when people add docs! However, small typo: "elemenets"

@chrisvxd chrisvxd mentioned this pull request Dec 3, 2018
@hipstersmoothie
Copy link
Contributor Author

@chrisvxd typo fixed!

@chrisvxd chrisvxd merged commit b1eb6a5 into chrisvxd:master Dec 3, 2018
@chrisvxd
Copy link
Owner

chrisvxd commented Dec 3, 2018

@hipstersmoothie 👏 thank you! Merged!

NB I squashed into conventional commit format, so you might want to reset your head to master.

@chrisvxd
Copy link
Owner

chrisvxd commented Dec 3, 2018

@hipstersmoothie just released v1.4.0 with your fixes!

@hipstersmoothie
Copy link
Contributor Author

hipstersmoothie commented Dec 3, 2018 via email

@chrisvxd
Copy link
Owner

chrisvxd commented Dec 3, 2018

No worries about commit format! I tend to squash most PRs that come through at the moment since many people aren't familiar with conventional commits.

It's another place for me to add linting, though!

@hipstersmoothie hipstersmoothie deleted the psuedo-elements branch December 3, 2018 17:54
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.

2 participants