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

fix: use matchPath to trick reach router to match router #11

Conversation

apaniel
Copy link
Contributor

@apaniel apaniel commented Sep 26, 2019

Fixes page going blank mentionend in: #5

For the plugin to properly work needs the #9 merged as well

By setting a wildcard in the matchpath the routing at component level is disabled, as it will accept any path when setting the path in the gatsby core production app

image

Also a check for pagePath has been added to fix the exception happening on gatsby develop

@xavivars
Copy link

Temporarily, while #9 and #11 get merged I've published a fork of this plug-in with both PRs merged as https://www.npmjs.com/package/@xavivars/gatsby-plugin-static-site

@wardpeet
Copy link
Owner

@apaniel90vp could you create a reproduction of the issue you're having, so I can add it to the e2e tests

@apaniel
Copy link
Contributor Author

apaniel commented Nov 17, 2019

Sure, basically the page goes blank when going from the initial page to a second one. As the url keeps being the same, and reach router is configured to show different components per page depending on the url, the router's path for the second page will never match.

Also #11 checks that pagePath exists, as there is a check to validate that is development that seems that is not working anymore 'if (!loader) {
return;
}
'

@wardpeet
Copy link
Owner

I'm creating a new PR to check for development mode in gatsby. Sadly, I still don't follow 100% what the blank page is all about. Could you create a reproduction or show me some urls. My e2e-test now loads a non Gatsby page and routes to a gatsby site but I might not understand your use case.

@apaniel
Copy link
Contributor Author

apaniel commented Nov 17, 2019

I won't be near a computer until tomorrow, but I can tell you how to see what the blank page is.
@xavivars has a fork repo of the ' `Gatsby Default Starter', where gatsby have been changed to in order to simulate the site flow for different MFEs:
https://github.com/xavivars/gatsbybug

By updating to the latest Gatsby version and to the latest static plugin version on that fork, when going from page 1 to page 2 you will see that the page shows nothing, and that is what #11 is fixing.

@xavivars
Copy link

The bug here only reproduces when you're serving the Gatsby app behind a las reverse proxy, changing the the public facing urls from the ones Gatsby exposes. Without this PR, reach-router prevents the page from being rendered at all.

If you look at version 0.0.1 of this plug-in, it was working because we're where changing Gatsby's page url to match window.location, so routing was working.. But with the approach after 0.1, where we do not change Gatsby url at all and simply play with the loader, router expects the url to be Gatsby's url

@wardpeet
Copy link
Owner

wardpeet commented Nov 17, 2019

what happens when you use pathPrefix and set it to /notworking as well?

@xavivars
Copy link

The piece you're probably missing is we do not access the HTML files via published URL, but always acces it to via a reverse proxy..

Imagine a mother server, running in localhost:12345, than when you access /one it proxies to the Gatsby app /page-1,when accessing /two, it is goes to your Gatsby app /page-2, and when accessing /three, it is goes to to example.com/foobar.

Those /one and /two are the ones that become blank, because Gatsby router only expects them to be loaded via /page-1 one /page-2

@apaniel
Copy link
Contributor Author

apaniel commented Nov 18, 2019

Yep, sorry, I forgot the most important part.
To replicate this behavior locally I do a build, and serve the files from a different route with serve npm package

@wardpeet wardpeet changed the title Feature/disable component routing with wildcard fix: use matchPath to trick reach router to match route Nov 26, 2019
@wardpeet wardpeet force-pushed the feature/disable-component-routing-with-wildcard branch from 6768da7 to a2ec250 Compare November 26, 2019 21:43
@wardpeet
Copy link
Owner

When tests are green I'll be merging and I'll do a publish. Thanks a ton!

@wardpeet wardpeet changed the title fix: use matchPath to trick reach router to match route fix: use matchPath to trick reach router to match router Nov 26, 2019
Copy link
Owner

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @apaniel90vp this is a great fix! I've added a test case for it so we don't regress.

Sorry to keep you waiting but this truly is amazing! 😍

@wardpeet wardpeet merged commit 24edf13 into wardpeet:master Nov 26, 2019
@wardpeet
Copy link
Owner

Published in v0.2.1

@xavivars
Copy link

@wardpeet we LOVE you!

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

Successfully merging this pull request may close these issues.

3 participants