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

Port from Batfish to Underreact #55

Merged
merged 14 commits into from
Nov 30, 2018
Merged

Port from Batfish to Underreact #55

merged 14 commits into from
Nov 30, 2018

Conversation

danswick
Copy link
Contributor

@danswick danswick commented Nov 15, 2018

See https://github.com/mapbox/frontend-platform-team/issues/32. For sites like this one, which do not need to generate multiple HTML files, @mapbox/frontend-platform has a new favored tool: Underreact. It's significantly simpler than Batfish, and is using the latest, fastest versions of Webpack and Babel — so it's the better choice for any sites that don't need Batfish's HTML generation.

A few notes about the changes in this PR:

  • I used <link> and <script> tags in the HTML to load mbx-assembly.
  • The new app.js component is just the content of the old src/docs/app.js.
  • browserslist: ['defaults'] means Underreact won't bother building for IE11, because this is an internal site (that should speed things up).
  • Babel did not like the Object: type here and I'm not familiar enough with Babel to configure my way around that issue, so I just removed it.

Next steps:

  • Get the page to render 😬
  • Update tests

@davidtheclark: I would love to talk through this a bit with you tomorrow. I am a bit fuzzy on what's going on with the Babel 7 updates I made here and I am still not entirely sure why the page isn't being rendered.

@danswick
Copy link
Contributor Author

Ok, after much flailing, I think this is ready to have its WIP tag removed. Tests are passing** and the page is rendering.

** tests are passing locally, but Travis is failing because it can't find @mapbox/underreact. @kepta: when I try to go to https://www.npmjs.com/login?next=/package/@mapbox/underreact/v/0.1.5 (or similar), I'm prompted to log in, which makes me think the package has recently become private.

@danswick danswick changed the title [WIP] Port from Batfish to Underreact Port from Batfish to Underreact Nov 16, 2018
@kepta
Copy link
Contributor

kepta commented Nov 16, 2018

** tests are passing locally, but Travis is failing because it can't find @mapbox/underreact. @kepta: when I try to go to https://www.npmjs.com/login?next=/package/@mapbox/underreact/v/0.1.5 (or similar), I'm prompted to log in, which makes me think the package has recently become private.

Looks like I have been mistakingly publishing it as private. I have publicly published it now and things should be working fine. Sorry about that.

.gitignore Outdated
@@ -3,6 +3,7 @@ node_modules
coverage
.DS_Store
_batfish*
_underreact-site
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's upgrade to the latest version of Underreact, in which case this will be _site.

.gitignore Outdated
@@ -3,6 +3,7 @@ node_modules
coverage
.DS_Store
_batfish*
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we delete this line?

src/index.js Outdated
@@ -0,0 +1,8 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

If this file is specific to docs, lets put it in src/docs.

@@ -0,0 +1,11 @@
'use strict';
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this for the docs or the test cases? Let's run both with Underreact.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@davidtheclark I'm not totally clear on how we would use Underreact for both the docs and the test-cases app in the same project.

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you looked at how each app works now, without Underreact? That would be the place to start.

Underreact commands have a --config option that you can use in order to store two different configs in one repo and run them in different Underreact processes.

Copy link
Contributor

Choose a reason for hiding this comment

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

@kepta
Copy link
Contributor

kepta commented Nov 19, 2018

Looks like this might be a great place to enable hot reloading feature of Underreact 🔥. We can either add it in this PR or I can send another PR to specifically enable it.

@danswick
Copy link
Contributor Author

I've done some reorganizing here that I hope will make the project easier to maintain:

  • Moved docs and the test-cases-app into their own directories separate from the source components.
  • Finished scaffolding for the docs page's port to underreact.
  • Begain porting the test-cases-app to underreact, but hit a dead-end trying to get it working (and also got myself all kinds of turned around trying to get eslint configured). Underreact seems to be building the page without issue and my React chrome dev tools indicate that the test cases component and ReactTestKitchen component are being created, but they're not being populated with anything and are not throwing any errors. I'm a bit lost on where things are going wrong and could use some backup if anyone from @mapbox/frontend-platform is wiling to take a look with me.

@kepta
Copy link
Contributor

kepta commented Nov 21, 2018

@danswick this was an interesting bug. I found that the bug is with the way we are using the basePath as '/mr-ui/test-cases-app', but the react-test-kitchen expects the basePath to be / and that's why the client side routing in rtk was wasn't outputting anything.

https://github.com/mapbox/react-test-kitchen/blob/1dbc8fb4e33c86cd02b66bd3f077587abe287a42/src/react-test-kitchen.js#L19-L23

We can probably send a fix to rtk to understand base paths or you can simply use / to keep it happy 😅.

Some notes on the bug hunt 👨‍🚒 :

  • The way we are auto-generating the files is pretty confusing to me (Maybe it is just me being unfamiliar with the rtk testing pattern).
  • Also, I wasn't careful to see that budo server is also being used and the fact that you reorganised the repo structure made the auto scripts generation broken.
  • If it is not too much of a trouble, I suggest saving the repo structure change to a separate issue/PR. This would make it easier to grok at the git diff and also keep only changes relevant to porting of Underreact in this PR.

@davidtheclark
Copy link
Contributor

I suggest saving the repo structure change to a separate issue/PR

Yes, definitely.

@danswick
Copy link
Contributor Author

Wow, thanks for tracking that down, @kepta! I can reorganize the structure for sure. The reason I changed it in the first place was that I found it confusing to have two web apps that reference the component source, but the component source lives alongside just one of the apps. So I separated everything just to help conceptualize which parts were interacting with what. I can totally see how the diff would be hard to make sense of in this state.

@davidtheclark
Copy link
Contributor

I found it confusing to have two web apps that reference the component source, but the component source lives alongside just one of the apps

I don't think I understand the confusion here. We have src/components, src/docs, and src/test-cases, so the source components are already alongside both apps.

@danswick
Copy link
Contributor Author

Thanks for all of the feedback, @kepta and @davidtheclark. I went ahead and fixed up the project structure, swapped the test cases app to a / basepath (thanks for that hint, @kepta! side note: I started experimenting with configurable basepath in rtk here, but was having some trouble and opted to stick with a basepath of / since the test cases app is really only ever used locally), and updated snapshots to get tests passing. Would love another review now that the diff is more manageable 🙏

Copy link
Contributor

@davidtheclark davidtheclark left a comment

Choose a reason for hiding this comment

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

Fantastic, @danswick. I tried it out locally and had no problems at all. Seems like you got it 👍 🍕

.artifacts.yml Outdated
@@ -0,0 +1,3 @@
version: v1
defaults:
- publisher
Copy link
Contributor

Choose a reason for hiding this comment

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

Mr UI isn't currently being published with Publisher, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yowza. I just got into Underreact robot mode and put this here automatically. I can remove.

.eslintignore Outdated
@@ -6,3 +6,5 @@ src/docs/data
pkg
src/test-cases-app/component-index.js
dist
*underreact.config.js
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be **/underreact.config.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works this way, but **/*underreact.config.js is more precise.

@@ -6,3 +6,5 @@ src/docs/data
pkg
src/test-cases-app/component-index.js
dist
*underreact.config.js
html.js
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, we shouldn't need to do this. But I don't want to clog up the PR for linting. Let's sort it out after the merge. (Hint: I think we'll use ESLint's overrides option.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good 👍

@@ -5,9 +5,8 @@ require('hard-rejection/register');
const fs = require('fs');
const path = require('path');
const pify = require('pify');

Copy link
Contributor

Choose a reason for hiding this comment

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

👹

const excludeDirs = new Set(['utils']);
const srcRoot = path.resolve(__dirname, '../src/components');
const srcRoot = path.resolve(__dirname, '../src/components/');
Copy link
Contributor

Choose a reason for hiding this comment

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

👹

(This change shouldn't make any difference, right?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👺


module.exports = () => {
return {
siteBasePath: '/mr-ui/docs',
Copy link
Contributor

Choose a reason for hiding this comment

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

The true base path is just /mr-ui, right? https://mapbox.github.io/mr-ui/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yep! This is a gremlin from when I was trying to give docs and test-cases-app their own base paths under mr-ui 😬

<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link href="https://api.mapbox.com/mapbox-assembly/mbx/v0.26.0/assembly.min.css" rel="stylesheet">
<script async src="https://api.mapbox.com/mapbox-assembly/mbx/v0.26.0/assembly.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 it's suspicious to me that we have different version of Assembly in the test cases and docs. Are you copying a mistake already in place, or is this a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like it was already in place, but I just bumped them both up to 0.28.1 and tested locally and everything looks good 👍

@danswick danswick merged commit 0b06b39 into master Nov 30, 2018
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.

None yet

3 participants