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

Enhance getProps to Extract Dynamic Route Parameters #1105

Open
wants to merge 5 commits into
base: 5.x
Choose a base branch
from

Conversation

dsfx3d
Copy link

@dsfx3d dsfx3d commented Apr 4, 2023

This PR improves the getProps function by enabling it to extract dynamic route parameters and include them in the final props object. These modifications enhance the functionality of single-spa applications by providing developers access to dynamic route parameters within the app props.

resolves #744

@github-actions
Copy link

github-actions bot commented Apr 4, 2023

File size impact

dist (+6,178 bytes)
Overall impact on dist files size
Diff master after merge
+6,178 329,325 335,503
Detailed impact on dist files size
File Diff master after merge Event
lib/es2015/single-spa.dev.js +935 55,235 56,170 changed
lib/es2015/single-spa.min.js +421 18,436 18,857 changed
lib/esm/single-spa.dev.js +1,084 59,471 60,555 changed
lib/esm/single-spa.min.js +438 20,885 21,323 changed
lib/system/single-spa.dev.js +1,282 69,444 70,726 changed
lib/system/single-spa.min.js +434 20,913 21,347 changed
lib/umd/single-spa.dev.js +1,150 63,795 64,945 changed
lib/umd/single-spa.min.js +434 21,146 21,580 changed
Impact on dist files cache

8 files in you users cache are now outdated because their content have changed.

Bytes outdated
329,325
Generated by file size impact during file-size-impact#5456823271

Copy link
Member

@joeldenning joeldenning left a comment

Choose a reason for hiding this comment

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

Please add tests.

const result = assign({}, customProps, {
name,
mountParcel: mountParcel.bind(appOrParcel),
singleSpa,
route: {
Copy link
Member

Choose a reason for hiding this comment

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

This new prop would need to be documented with a pull request to https://github.com/single-spa/single-spa.js.org. Please open a pull request with it.

The route name for the prop is one that should be considered. In react-router, I believe it's called params rather than route. I think I'm open to either name, but we should think about it carefully.

Copy link
Author

Choose a reason for hiding this comment

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

The name route may be good for potential enhancements in the future to keep similar props under the same namespace. For example, search/query.
What do you think?

const result = assign({}, customProps, {
name,
mountParcel: mountParcel.bind(appOrParcel),
singleSpa,
route: {
get params() {
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer not using a Javascript getter here, since it has performance implications just for accessing props.route. Ideally we'd calculate the route params once per URL change rather than every time any code does props.route. I haven't thought through whether it would be possible to do that, but it's something that should be explored. The toDynamicPathRegexInfo function is complex enough that I don't want it running frequently

Copy link
Author

Choose a reason for hiding this comment

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

I don't think there's a foul proof native way of listening to URL changes. We may try building route object whenever navigateToUrl is invoked.

will it be good enough or we may try something else?

Copy link
Author

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

@dsfx3d I don't think navigateToUrl is a good solution because it is not the only or even primary way people use to change the URL. I think it should be done in an event handler that fires when the URL changes. Just my $0.02.

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.

Read params from html route structure, pass via props
3 participants