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

@html does not update on hydration #148

Closed
9 tasks done
hobbes7878 opened this issue Apr 6, 2024 · 3 comments · Fixed by #150
Closed
9 tasks done

@html does not update on hydration #148

hobbes7878 opened this issue Apr 6, 2024 · 3 comments · Fixed by #150
Assignees
Labels
bug Something needs fixing

Comments

@hobbes7878
Copy link
Member

hobbes7878 commented Apr 6, 2024

Inventory of the components using @html tags that will need to be updated to get around this issue:

  • BodyText
  • EndNotes
  • GraphicBlock
  • Headline
  • InfoBox
  • PhotoPack
  • Scroller
  • SimpleTimeline
  • Table

There's a few longstanding issues on the Svelte repo about this, amazingly.

A workaround is to set innerHtml with an action, which is what I guess we'll have to do before we can have live updating previews from RNGS.io working..

<script>
function setInnerHTML(node, html) {
    node.innerHTML = html;
    return {
      destroy() {
        node.innerHTML = '';
      },
    };
  }
</script>

<div use:setInnerHTML="{marked.parse(text)}"></div>

<style>
  div {
    display: contents;
  }
</style>

Honestly, amazed this hasn't come up for me before...

Will likely need to scrub all our components for this, but for sure BodyText is first up.

@hobbes7878 hobbes7878 added the bug Something needs fixing label Apr 6, 2024
@hobbes7878 hobbes7878 self-assigned this Apr 6, 2024
@hobbes7878
Copy link
Member Author

hobbes7878 commented Apr 6, 2024

This is tricky b/c this text is not prerendered using an innerHTML action...

Can do this to get it back, but I need to test if this is gonna lead to flashes on prod stuff.

<script>
  import { building } from '$app/environment';

  function setInnerHTML(node, html) {
    node.innerHTML = html;
    return {
      destroy() {
        node.innerHTML = '';
      },
    };
  }
</script>

{#if building}
  <div>
    {@html marked.parse(text)}
  </div>
{:else}
  <div use:setInnerHTML="{marked.parse(text)}"></div>
{/if}

<style>
  div {
    display: contents;
  }
</style>

@hobbes7878
Copy link
Member Author

hobbes7878 commented Apr 7, 2024

OK, it looks like the above workaround doesn't lead to flashes that I can see and still prerenders. It's extra processing time on load, but I don't know have many better ideas at this point.

Idea would be to make a standalone component for markdown text, I suppose, and replace all the @html refs with it.

Trouble is building state can't rely on SvelteKit variables, which causes trouble in SREP land where we use Vite alone. Possible solutions, all bad:

  • Make a store that we set in SvelteKit projects to mirror building..
    • There is no equivalent in SREP Vite-only projects, so we'd need to set a default that would always be true for SREPs. If that's using @html then we've locked SREPs out of live endpoint updates.
  • Actively check for Node v. Browser context by checking window or something??
    • Really hacky...
  • Look at alternative solutions that actively parse markdown into Svelte text components like svelte-markdown
    • ... but that's a monstrous dependency, not super actively maintained.

Sucks, all of these, really..

@hobbes7878
Copy link
Member Author

Noting the main issue tracking this in the Svelte repo: sveltejs/svelte#8213
And a PR worth watching: sveltejs/svelte#9063

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something needs fixing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant