question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Static content in <Raw/> disappears after component refresh

See original GitHub issue

Using crank v0.4.0 🎉

I have a component that renders some markdown using <Raw/> and noticed that after refreshing the component the markdown would disappear.

For example, the static content in the second <Raw/> tag will disappear after clicking the button to refresh. However, the dynamic content in the first one will still render correctly.

function* App() {
  let refreshCount = 0;

  const refresh = () => {
    refreshCount += 1;
    this.refresh();
  };

  for (const {} of this) {
    yield (
      <Fragment>
        <div>
          <Raw value={`<h1>Dynamic content ${refreshCount}</h1>`} />
          <Raw value="<h2>Static <em>raw</em> content</h2>" />
        </div>
        <button type="button" onclick={refresh}>
          Refresh
        </button>
      </Fragment>
    );
  }
}

Codesandbox example: https://codesandbox.io/s/raw-tag-content-disappearing-unngm

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
waynebaylorcommented, Oct 28, 2021

I created PR #224 with a change to updateRaw. If you want I can look into changing what renderer.parse() returns, just let me know.

1reaction
waynebaylorcommented, Oct 27, 2021

@brainkim In updateRaw I can see how refreshing the component skips over the conditional and returns ret.value:

function updateRaw<TNode, TScope>(
  renderer: RendererImpl<TNode, TScope, TNode, unknown>,
  ret: Retainer<TNode>,
  scope: TScope | undefined,
  oldProps: Record<string, any> | undefined
): ElementValue<TNode> {
  const props = ret.el.props;
  if (typeof props.value === 'string') {
    if (!oldProps || oldProps.value !== props.value) {
      ret.value = renderer.parse(props.value, scope);
    }
  } else {
    ret.value = props.value;
  }

  return ret.value;
}

What I’m not sure about is where the fix should go. Does updateRaw need to be changed or is it just being passed a bad value (i.e. ret.value is incorrect)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React component content disappears after page refresh
I am new to react and am having trouble figuring out why the data inside my Content component does not re-render on refresh....
Read more >
Fast refresh not working properly due to page reload ... - GitHub
Hi, I have the same issue. To reproduce it: import a function in react component then the same function import in your _middleware.js....
Read more >
Basic Features: Fast Refresh - Next.js
Next.js' Fast Refresh is a new hot reloading experience that gives you instantaneous feedback on edits made to your React components.
Read more >
Server-side rendering - Apollo GraphQL Docs
Server-side rendering (SSR) is a performance optimization for modern web apps. It enables you to render your app's initial state to raw HTML...
Read more >
Handling common JavaScript problems - MDN Web Docs
Now we'll look at common cross-browser JavaScript problems and how to fix them. This includes information on using browser dev tools to track ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found