Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

feat(routes): childRoutes are not required for root module #657

Merged
merged 8 commits into from
Jan 26, 2022

Conversation

bishnubista
Copy link
Contributor

@bishnubista bishnubista commented Jan 21, 2022

Description

Motivation and Context

Root modules are required to have childRoutes. With this change, childRoutes will be optional.

How Has This Been Tested?

Ran one-app server locally with root module, with and without child routes.

Test cases are written for new files and files changed.

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • [ X] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (adding or updating documentation)
  • Dependency update
  • Security update

Checklist:

  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • These changes should be applied to a maintenance branch.
  • This change requires cross browser checks.
  • Performance tests should be ran against the server prior to merging.
  • This change impacts caching for client browsers.
  • This change impacts HTTP headers.
  • This change adds additional environment variable requirements for One App users.
  • I have added the Apache 2.0 license header to any new files created.

What is the Impact to Developers Using One App?

Root modules no longer requires childRoutes. If childRoutes are not provided, path is added, which will render root component.

@bishnubista bishnubista requested review from a team as code owners January 21, 2022 00:08
@github-actions
Copy link
Contributor

github-actions bot commented Jan 21, 2022

📊 Bundle Size Report

file name size on disk gzip
app.js 314.2KB 93.2KB
runtime.js 15.6KB 5.5KB
vendors.js 129.1KB 40KB
app~vendors.js 427.4KB 110.5KB
service-worker-client.js 17.1KB 5.3KB
legacy/app.js 334.8KB 98KB
legacy/runtime.js 15.6KB 5.5KB
legacy/vendors.js 189.4KB 51.7KB
legacy/app~vendors.js 450.4KB 116.2KB
legacy/service-worker-client.js 17.6KB 5.5KB

Generated by 🚫 dangerJS against 4a937e0

…o feat/childRoutes-not-required-in-root-module
src/universal/routes.jsx Outdated Show resolved Hide resolved
src/universal/routes.jsx Outdated Show resolved Hide resolved
@10xLaCroixDrinker 10xLaCroixDrinker requested a review from a team January 24, 2022 18:48
Copy link
Member

@Matthew-Mallimo Matthew-Mallimo left a comment

Choose a reason for hiding this comment

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

Approving the code changes, but we should document this functionality

@bishnubista
Copy link
Contributor Author

Approving the code changes, but we should document this functionality

I will do it. thanks.

@bishnubista bishnubista enabled auto-merge (squash) January 24, 2022 19:18
@@ -0,0 +1,3 @@
const hasChildRoutes = (module) => (module !== null && typeof module === 'object') && !!module.childRoutes;
Copy link
Member

Choose a reason for hiding this comment

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

This file needs the license header

@@ -0,0 +1,11 @@
import hasChildRoutes from '../../../src/universal/utils/hasChildRoutes';
Copy link
Member

Choose a reason for hiding this comment

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

License header is also needed here

@@ -39,7 +39,7 @@ Enables components and modules to define their own child routes. `childRoutes` c
route, array of routes or a function which accepts the Redux store as the sole argument and returns
a single route or array of routes.

One App requires the Root Module to have at least one child route defined. This can be either `<Route>` or `<ModuleRoute>` with a `path`.
`childRoutes` is optional for Root Module. `childRoutes` can be either `<Route>` or `<ModuleRoute>` with a `path`. If `childRoutes` is not defined, default path `/` is added to RootRoute prop in one app.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`childRoutes` is optional for Root Module. `childRoutes` can be either `<Route>` or `<ModuleRoute>` with a `path`. If `childRoutes` is not defined, default path `/` is added to RootRoute prop in one app.
`childRoutes` is optional for Root Module. `childRoutes` can be either `<Route>` or `<ModuleRoute>` with a `path`. If `childRoutes` is not defined, the default path `/` is added to the root route.

* permissions and limitations under the License.
*/

const hasChildRoutes = (module) => module !== null && typeof module === 'object' && !!module.childRoutes;
Copy link
Contributor

@JAdshead JAdshead Jan 25, 2022

Choose a reason for hiding this comment

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

as null and undefined are falsy this null check is redundant, also not a fan of the type check as i don't think its needed, anything that would throw a type error is considered falsy, anything else (string, int,symbol etc) will return undefined.

Suggested change
const hasChildRoutes = (module) => module !== null && typeof module === 'object' && !!module.childRoutes;
const hasChildRoutes = (module) => module && !!module.childRoutes;

If you are desperate for a boolean

Suggested change
const hasChildRoutes = (module) => module !== null && typeof module === 'object' && !!module.childRoutes;
const hasChildRoutes = (module) => !!module && !!module.childRoutes;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JAdshead Updated.

infoxicator
infoxicator previously approved these changes Jan 25, 2022
@bishnubista bishnubista merged commit 0926fb2 into main Jan 26, 2022
@bishnubista bishnubista deleted the feat/childRoutes-not-required-in-root-module branch January 26, 2022 16:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants