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

Inline <a> tag taking full horizontal width on Web. #514

Closed
7 of 15 tasks
parasharrajat opened this issue Aug 6, 2021 · 18 comments
Closed
7 of 15 tasks

Inline <a> tag taking full horizontal width on Web. #514

parasharrajat opened this issue Aug 6, 2021 · 18 comments
Labels
bug Crush'em all.

Comments

@parasharrajat
Copy link

parasharrajat commented Aug 6, 2021

Decision Table

  • My issue does not look like “The HTML attribute 'xxx' is ignored” (unless we claim support for it)
  • My issue does not look like “The HTML element <yyy> is not rendered”

Good Faith Declaration

Description

In the Older version of RNRH the <code> element use to behave inline but now. it takes the full width of the screen.

I think this change has affected every tag. For example, if you add a link element, it is clickable from empty space on the web.

image
In the above image click the far right and it goes to that link on the web.

WEB

Inline Tag expands to the full width of the parent.

React Native Information

System:
    OS: Linux 5.10 Manjaro Linux
    CPU: (16) x64 Intel(R) Core(TM) i7-10870H CPU @ 2.20GHz
    Memory: 363.11 MB / 15.47 GB
    Shell: 5.1.8 - /bin/bash
  Binaries:
    Node: 14.16.0 - /usr/bin/node
    Yarn: Not Found
    npm: 6.14.13 - ~/.npm-globals/bin/npm
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 29, 30
      Build Tools: 29.0.2, 29.0.3, 30.0.3
      System Images: android-29 | Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.2 AI-202.7660.26.42.7351085
  Languages:
    Java: 1.8.0_292 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: 4.13.1 => 4.13.1 
    react: ^17.0.2 => 17.0.2 
    react-native: 0.64.1 => 0.64.1 
  npmGlobalPackages:
    *react-native*: Not Found

RNRH Version

V6.0.0-beta.8

Tested Platforms

  • Android
  • iOS
  • Web
  • MacOS
  • Windows

Reproduction Platforms

  • Android
  • iOS
  • Web
  • MacOS
  • Windows

Minimal, Reproducible Example

https://snack.expo.dev/hGHmxvgL7

Additional Notes

I compared the older alpha version of the V6 to the Beta version. There is only one difference that there used to be a wrapping node in DOM around the main tag node but now it's not there. So Body tags flex:column styling is causing it to expand to full-width.

The structure is like this

 <html-node>
   <body-node>
     <code-node>

previously

 <html-node>
   <body-node>
     <wrapper-node>
       <code-node>
@parasharrajat parasharrajat added the bug Crush'em all. label Aug 6, 2021
@jsamr
Copy link
Collaborator

jsamr commented Aug 7, 2021

@parasharrajat Interesting case; react-native-web seems to set align-items to stretch which causes the spanning. If we force it to flex-start, the intended behavior is reinstated. You are right about the alluded change in behavior :

// When a TPhrasing node is anonymous and has only one child, its
// rendering amounts to rendering its only child.
if (props.tnode.tagName == null && props.tnode.children.length <= 1) {
return React.createElement(TNodeChildrenRenderer, {
tnode: props.tnode
});
}

This change was introduced to lighten the render tree, with the additional benefit of leveraging a couple of bugs with React Native nested Text. I still have to think more deeply about the issue before providing a fix which might introduce unintended behaviors. In the meantime, you could try something along defaultViewProps={{ style: { alignItems: "flex-start" } }} for Web and see how it behaves.

@jsamr jsamr changed the title Inline <code> block taking full horizontal width on Web. Inline <a> tag taking full horizontal width on Web. Aug 7, 2021
@parasharrajat
Copy link
Author

Thanks @jsamr , I will try that.

@parasharrajat
Copy link
Author

This seems to work fine. Please let me know if you have plans to fix this issue in the core library. I can track this issue and upgrade the lib as soon as it's done.

@jsamr
Copy link
Collaborator

jsamr commented Aug 7, 2021

@parasharrajat Sure, I'll let you know!

@parasharrajat
Copy link
Author

parasharrajat commented Aug 12, 2021

Another side-effect of that change. Check out the first Inline code block behaving like a code block on Web.

Screen Shot 2021-08-13 at 01 43 47

@jsamr
Copy link
Collaborator

jsamr commented Aug 13, 2021

@parasharrajat is that an effect of alignItems or of the removal of the wrapper?

@parasharrajat
Copy link
Author

I think Removal of the wrapper. Inside flex-container inline node is behaving block. I added Text inside the TDefaultRenderer which fixed it.

@jsamr
Copy link
Collaborator

jsamr commented Aug 15, 2021

@parasharrajat If you're willing to provide a reproduction for this second issue, I'd be happy to investigate.

As per your first issue, I think a better solution would be to only target the body tag:

See https://snack.expo.dev/@jsamr/rnrh-web-bug

Otherwise, unintended side-effect might proof hard to foresee.

@parasharrajat
Copy link
Author

parasharrajat commented Aug 18, 2021

@jsamr Here you go https://snack.expo.dev/@parasaharrajat/rnrh-web-bug.

There is another issue that I am facing. Expensify/App#4733. The same code was working previously.

@parasharrajat
Copy link
Author

For now, I suggest that you revert those changes as it causing a lot of issues and then carefully migrate. I would like to keep the latest v6 due to stability and some good feature.

@jsamr
Copy link
Collaborator

jsamr commented Aug 19, 2021

@parasharrajat I am probably going to provide a 6.0.6-beta.0 with a prop to disable this behavior so that you can quickly provide a "fix", and after that take some time to investigate further the implications of that change. I can't revert the behavior without introducing a breaking change and potentially disrupting many consumers. I must stress that many bugs exist with nested text in React Native and one main reason for this change was to mitigate these whenever possible. I'm pretty busy right now, so expect a beta before the end of the week. If you are willing to, you can also provide a PR (the name of the prop should be disableTPhrasingNodesReduction) and I'll take 5 minutes to merge and publish.

@parasharrajat
Copy link
Author

Thanks for prompt action @jsamr. It sounds great. I will look into the codebase to understand it and try to put up a PR to disable this behaviour behind the flag. Could you please link me to the PR where you made this change or the commit? It would help me quickly get familiar with the main area.

@jsamr
Copy link
Collaborator

jsamr commented Aug 19, 2021

Here it is: dad450d
If you have any "lively" question, ping me in our Discord!

PS: a better name for the prop: preserveAnonymousTPhrasingNodes and a description:

/**
* When `true`,  preserve anonymous {@link TPhrasing} nodes parents of lonely {@link TText} nodes at render time instead of bypassing them and rendering their child directly.
*
* @defaultValue `false`
*/

@jsamr
Copy link
Collaborator

jsamr commented Aug 22, 2021

Here you go https://snack.expo.dev/@parasaharrajat/rnrh-web-bug.

@parasharrajat Not sure what is the expected behavior versus what is observed? I can't find anything surprising in this snippet (Web), what did I miss?

image

@parasharrajat
Copy link
Author

Previously, the second code block used to wrap same as first code block where border and background also wrap with text. It used to behave inline but now it is block. Text is wrapping but border and background is surrounding whole text and its not breaking on each line.

@jsamr
Copy link
Collaborator

jsamr commented Aug 22, 2021

@parasharrajat Got you, I tried your example with alpha-20:
image

@jsamr jsamr closed this as completed in 90b8a3d Aug 22, 2021
@jsamr
Copy link
Collaborator

jsamr commented Aug 22, 2021

@parasharrajat You can now set bypassAnonymousTPhrasingNodes prop to false in version 6.1.0-alpha.0; hope that will help! Let me know.

@parasharrajat
Copy link
Author

Thanks, I will take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Crush'em all.
Projects
None yet
Development

No branches or pull requests

2 participants