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

Content flashes then disappears (Can't hydrate document) #76

Closed
jimafisk opened this issue Oct 22, 2020 · 17 comments
Closed

Content flashes then disappears (Can't hydrate document) #76

jimafisk opened this issue Oct 22, 2020 · 17 comments
Labels
bug Something isn't working high high priority

Comments

@jimafisk
Copy link
Member

I'm putting this issue here as a placeholder for when someone inevitable hits it. In release v0.2.39 we modified the svelte node_module in order to work with plenti's new hydration setup. You need that modified version in order to have things work properly.

What you may experience: On the initial page load, when plenti tries to hydrate the static HTML, some of the content will be removed. Then if you try to navigate to other pages, the navbar will remain but all the content will be gone.

What is causing this: This is happening because we're trying to hydrate the document which isn't currently supported by Svelte. You're likely using the standard version of Svelte because you ran an npm update or something similar. If you're using the modified node_modules/svelte/internal/index.mjs that ships with Plenti, you should not experience this issue.

Long-term fix: You will continue to hit this if you try to update Svelte to a newer version using NPM because the standard lib does not have the fix. We have an open issue to discuss this with the maintainers, so hopefully future versions will accommodate this: sveltejs/svelte#5547. If the proposal is rejected I will have to create a custom injection (likely in cmd/gopack.go or cmd/npm_defaults.go) to add this, but it's not ideal given changing versions of svelte.

Here are the console errors you will see:

  • Firefox: DOMException: Node.insertBefore: Cannot have more than one Element child of a Document
  • Chrome: DOMException: Failed to execute 'insertBefore' on 'Node': Only one element on document allowed.
@jimafisk jimafisk added bug Something isn't working high high priority labels Oct 22, 2020
@jimafisk
Copy link
Member Author

Another important note: If you upgrade to v0.2.39, you will experience this on existing projects (that already have a node_modules folder) since they also do not have the modified version of svelte. The easiest fix is just to remove the existing node_modules/ folder (rm -R node_modules) then the next time you run plenti serve you should get the new, modified lib.

@jimafisk
Copy link
Member Author

jimafisk commented Dec 6, 2020

From https://lihautan.com/compile-svelte-in-your-head-part-1/#m-target-anchor:

Contains instructions to mount the elements into the target.

From https://stackoverflow.com/questions/47662168/why-i-couldnt-append-a-child-node-to-the-document-object-model-directly:

the Document can have only 1 type (HTML or XML) and 1 element/child (e.g <html>) and the element (<html> tag) can have multiple children (<body>, <head>, etc..), attributes, etc.. So the element (<html>) and its children can be appended to, but the document itself cannot.

Related issues:

@jimafisk
Copy link
Member Author

jimafisk commented Jul 3, 2021

It looks like this might be resolved: sveltejs/svelte@04bc37d

That's huge because it will allow folks to manage their own version of Svelte with NPM going forward. This is great if the version of Svelte included with Plenti falls behind or someone's requirements force them to lock to a specific version for whatever reason.

@jimafisk
Copy link
Member Author

jimafisk commented Jul 7, 2021

This should be resolved in v0.4.25.

@jimafisk jimafisk closed this as completed Jul 7, 2021
@roobyz
Copy link

roobyz commented Aug 3, 2021

hi @jimafisk, I believe that I am having the "same" issue, however it could be a new issue. I'm using using v0.4.26 to develop a new Plenti template using Tailwind CSS. I published my development site (https://www.quantifiedleap.com/) using this template to Cloudflare pages. Basically the content would flash and disappear as mentioned in this issue and Chrome would generate a misleading error in the console. This issue is not happening locally... only when pushed to Cloudflare pages.

That said, I implemented a work-around to "make" it work:

  1. Updated Svelte to 3.38.3 as mentioned above, which addressed the npm update issue.
  2. I published my site using the "development" files, which includes the live-reload.js script.
    • Chrome generates an error "Uncaught DOMException: The operation is insecure."
    • however the site works as expected

Thoughts?

@jimafisk
Copy link
Member Author

jimafisk commented Aug 3, 2021

Hi @roobyz, Quantified Leap is looking awesome 👍. Is this the repo for the base template: https://github.com/roobyz/plenti-compendium

When I inspect the site, it looks like the console errors are related to live reload:

Screenshot

live-reload

live-reload.js:18 Mixed Content: The page at 'https://www.quantifiedleap.com/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://www.quantifiedleap.com/reload'. This request has been blocked; this endpoint must be available over WSS.

and

Uncaught DOMException: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.
    at HTMLDocument.<anonymous> (https://www.quantifiedleap.com/spa/ejected/live-reload.js:18:12)

When you're running your build command during CI, are you passing the -L flag by chance? That flag should only be used for local development to automatically reload your browser when you make a local edit. If you're building in CI with a standard plenti build this might be a bug, because live-reload shouldn't be injected in that case! Thanks!

@roobyz
Copy link

roobyz commented Aug 3, 2021

Hi @jimafisk... thanks for the kudos. Need to wrap up the tag and category pages, and add maybe some api calls to wire up the send contact button, but it's definitely getting there. Thanks for helping to make this possible!

Yes, you found the repo for the base template.

Correct also, on the console errors. I am passing the -L flag as a work-around. It is strange because it works perfectly on my local machine with or without the -L flag. Passing the -L flag makes it work on Cloudflare pages like it does locally.

Without the -L the homepage flashes then disappears and tries to load the 404 page. Then it generates errors about not finding any images. If I comment out all the assets, I finally get:

  • Firefox: unreachable code after return statement
  • Chrome: Error with Feature-Policy header: Unrecognized feature: 'none'.

@jimafisk
Copy link
Member Author

jimafisk commented Aug 3, 2021

Any chance you could try building on Cloudflare without the -L again so I can see the broken site? Also if there are any errors / warnings during the build in CI you can share, that would be great!

@roobyz
Copy link

roobyz commented Aug 3, 2021

@jimafisk... As requested, I pushed the static files to Cloudflare pages without the -L. I literally get no error/warning messages or any other indication that anything should be wrong. Note that after the site load fails, the 404 page tries to load, and the console will say Uncaught (in promise) TypeError: image is undefined.

I am building the static site locally and then pushing the static files for Cloudflare pages to consume. Check out my scripts section of the package.json on plenti-compendium. Cloudflare pages supports a number of static site generators by default, but plenti isn't there yet. I could use Cloudflare workers to do it, but that was extra work and slower so I went with local build. ;-)

@jimafisk
Copy link
Member Author

jimafisk commented Aug 3, 2021

I think I've figured out what's going on here and I believe it's related to baseurls (#68). I spun up a version of your site and was having the same issue, but with a few tweaks it seems to be working now: https://jimafisk.github.io/plenti-compendium/.

There are two potential solutions:

  1. Update all your URLs to be relative like I did in my fork:
  1. Just remove <base href={base} /> entirely in layouts/global/head.svelte

Option two is probably the fastest / easiest since you're using a custom url. I only went with option one because my test site is hosted in a subfolder on github pages. Let me know if that gives you any trouble!

@roobyz
Copy link

roobyz commented Aug 3, 2021

Thanks @jimafisk! That sorted it. Funny thing is that I went through all the layout files and updated the URLs to account for baseurl and hadn't considered the css and json files.

The only "correction" I made to your updates above is that I fixed the "tailwind.source.css" located in the styles folder. This overwrites the "tailwind.global.css" in the assets folder when building for production (purge/minify) or development (complete tailwind css). ;-)

@jimafisk
Copy link
Member Author

jimafisk commented Aug 3, 2021

Ah yes that makes sense! Your theme is lovely, is it something you'd like to let other people use? I'd love to feature it on the website if that's something you're interested it: https://plenti.co/themes. No pressure if it's intended for your specific brand! Nice work :)

@roobyz
Copy link

roobyz commented Aug 3, 2021

Yes, my plan is to make the compendium template usable for others. I'll do some extra branding on my quantifiedleap site, beyond the template, which will be my own.

I made the template so that folks can modify key values on the index.json content to transform the site theme based on user preferences. To tweak my concept, I created three color schemes using css variables for light and dark themes. In addition, I've commented the layout files so that others can reverse-engineer and modify to their heart's content.

The template is not quite finished yet. I have a few TODOs:

  1. add Tags and Category pages
  2. add code to save the dark/light theme using localStorage
  3. add a "Sendgrid" API function for the contacts page
  4. update for WAI-ARIA
  5. add a detailed README.md that explains how to use the theme
  6. Maybe include some additional SEO tweaks and transform the template to the dynamic components approach you outlined on youtube

Any feedback or suggestions appreciated. ;-) Be nice to have at least points 1 and 2 finished before going "public". That said, it doesn't have to be perfect right away, right?

BTW, I created another project in parallel (articulatePost), so that I could write my posts in markdown, and transforms the posts to JSON. Mostly so that I could also cross-post RMarkdown files, provide code highlighting and Katex math capabilities for data science related projects.

@jimafisk
Copy link
Member Author

jimafisk commented Aug 4, 2021

That's awesome, thanks for helping grow the ecosystem! Cool idea to make customizable color themes, this will be a great base theme for people who want control over their branding without having to rig up the code themselves.

Your todo list makes a lot of sense, I'm excited for you to roll those features out. Just let me know if you hit any snags along the way, I'd be happy to take a look.

I'm always a fan of releasing early and making improvements over time. I just cloned your project into the https://github.com/plenti-themes/ org and gave you access. I figure this might help with discoverability as we add more themes and also gives them a consistent url, but if you'd prefer to continue working off your repo that's totally fine! I created a theme page for it on the website as well: https://plenti.co/themes/compendium. When you feel it's ready we can announce it on our social media and link back to your website or whatever channel you want to promote.

I'm sure folks from #75 would find articulatePost really helpful. I'll follow up there so they are aware.

@roobyz
Copy link

roobyz commented Aug 4, 2021

@jimafisk thanks for the support. Note that I updated the fork you made (https://plenti.co/themes/compendium), which includes my TODO list. Already crossed off #2 on the list. ;-)

Would you be open to a "zoom" call? It would be helpful to a) align around how my theme fits in with your vision, b) clear up some questions I have on some of my design choices, and c) get your thoughts/insights on the remaining action items. Also, is using the issues comment board the best way to discuss project design/direction? ;-)

@jimafisk
Copy link
Member Author

jimafisk commented Aug 4, 2021

Let's hop on a call! You're west coast right? My schedule is pretty flexible tomorrow (8/5) during the day, do you want to talk at 3pm EDT (12 noon PDT)? We can just use https://meet.jit.si/plentico unless you prefer a different service.

Yeah for now throwing ideas, questions, etc into issues is the easiest way to go. If that gets too cluttered down the road I might move things to a discussion board.

Thanks!

@roobyz
Copy link

roobyz commented Aug 4, 2021

Cool. That works for me. 12-12:30 PDT. https://meet.jit.si/plentico sounds perfect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high high priority
Projects
None yet
Development

No branches or pull requests

2 participants