-
Notifications
You must be signed in to change notification settings - Fork 3k
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
React Native Render HTML: whitespace collapsing #851
React Native Render HTML: whitespace collapsing #851
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great overall and thanks for these changes! Left a couple of quick comments about style. I'll leave testing to @AndrewGable.
@marcaaron Thanks for the feedback!! I'll wait for Andrew's input. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great! Two things:
- Looks like there are some conflicts, could you fix those?
- Can you run
npm run lint
, it looks like there are two super small lint issues. We usually would run these via GitHub Actions, but haven't set them up for forks quite yet.
preTagStyle, codeTagStyle and blockquoteTagStyle have been merged into tagStyles, since those styles are passed to custom renderers via "style" prop in the new v6 renderer API. It is more consistent with the recommended way to proceed with the new release of react-native-render-html.
A new RenderHTML component is available in src/components/RenderHTML.js. It lightens the aforementioned component, and help refine HTML logic. The new blockquoteRenderer has been dropped since it only inject styles to the renderer.
The component has been simplified from 3 to 2 target variants, and has been rewritten to fit the new Renderer API.
Those types were duplicated!
This variable is provided by React Native JavaScript environment, and required by react-native-render-html. Reference: https://reactnative.dev/docs/javascript-environment
The new version of this library already provide transpiled sources (no JSX).
448e48e
to
fc7e33f
Compare
@AndrewGable I made the requested changes:
Hope that's fine! I made a quick screenshot to make sure the result was identical (I wanted to test blockquote because a new custom renderer had been registered in master, but apprently the markdown parsing is not ready yet): |
Code is looking great, I am just working on some testing then I will ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests great. Thanks for the awesome PR! 👏
It was a pleasure working with you on this issue, I'd love for you to implement your suggestions and I will chat with @puneetlath about next steps to write up another agreement so we can get those implemented if you are up for it.
@AndrewGable Hey Andrew, the pleasure is shared! I would love to participate again. I'm currently working on the intermediary v5 release after which I'll have to port all new features (and deprecations) to v6. A new service could also be the opportunity for me to adapt this PR code to the yet evolving shape of the V6 API. To reassure you, I really think it will have greatly stabilized by the time of my next intervention. |
@jsamr - It looks like we are getting an error when we deployed this to production:
Do you have any ideas on this one? |
Looks like I should not have marked this comment as "off topic": #851 (comment) I can reproduce this by:
Looking into what's different between dev and prod webpack configs that could cause this. |
Yes, absolutely https://github.com/native-html/core/blob/bee4e1124449c993c0995b87a0c79316e20a6274/packages/transient-render-engine/src/flow/text-transforms.ts#L10 In the meantime, I'll publish a hotfix tomorrow in @native-html/transient-render-engine, disabling this behavior for east-asian characters, and bring it up here. Shall I open a distinct new PR? |
@AndrewGable I don't know whitch minifier you use with webpack, but I've seen people complaining about a similar issue with terser, see vuejs/vue#9456 (comment), or babel, see babel/babel#5564 (comment) My assumption would be that the minifier replaces '\uxxxx' sequences in strings with their unicode counterpart to save space, but that breaks regex instantiation. I think I'll just put the unicode sequences directly in the regex to prevent such minifier mangling, because if that's the issue, you won't be the last to face it! RIP DRY |
Yes we ran into this on web, using react-native-web. You can open up a new PR with this and the latest fixes as we reverted this PR specifically. That's an annoying bug! p.s. No rush on this! My fault for not testing a production build before deploying it 😄 |
Summary
6.0.0-alpha.76.0.0-alpha.8src/styles/StyleSheet
(styles are passed to custom renderers, thus there is no need to define distinct styles for code and pre tags)src/pages/home/report/ReportActionItemFragment.js
to theRenderHTML
component, adapted to RNRH v6InlineCodeBlock
and adapted its logic to the new APIpropTypes
forAnchorForCommentsOnly
__DEV__
global variable in webpack environment, required by react-native-render-html, see https://reactnative.dev/docs/javascript-environmentNotes
enableCSSInlineProcessing
prop. If you think you might need this feature, I can enable it.systemFonts
for that purpose (I've already registered all the fonts declared insrc/styles/fontFamily
).Suggestions
Dimension
API. It is known for being unreliable, (see Make a decision about the Dimensions module react-native-community/discussions-and-proposals#291). I recommenduseWindowDimensions
hook instead!.eslintrc.js
is inconfig
folder, which is non standard. Would be best if the linter config could be picked automatically by VSCode, very handy for format action!Future work
DefaultTagRenderer
prop in the renderer component (he would require that you pass down all the props). But I realize that you tamper with the URL for credentials. Instead, you would need to reuse the internal HTMLImageElement component. I haven't exported that yet in the new API, but I will do so soon (see Use internal default renderers logic in custom renderers meliorence/react-native-render-html#424). I could work on a new PR as part of a distinct service if you are interested.RenderHTML
instance, a new instance ofTRenderEngine
is created, with a big tree of objects representing the underlying models for HTML tags and CSS properties, which in turns depends on configuration (custom renderers, styles ... Etc). I am planning to provide two additional React components:TRenderEngineProvider
, which will take config props and create a React context providing one engine instance;RenderHTMLFragment
, which will consume the engine and build the react tree from html / uri.Considering the linear cost of re-instantiating an engine for each message in the thread, I truly believe it could make a very sensible addition.
Fixed Issues
Fixes https://github.com/Expensify/Expensify/issues/143758
Tests
Open a chat thread and make sure:
Screenshots
Android
iOS
Desktop
Web
I managed to run the dev server, but I couldn't get pass the login screen. The app complains it has no access to the API. I followed all steps detailed in this document, but looks like it wasn't enough.