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

ReactConfig lack of wildcard subdirectory search for adding components #526

Closed
tokyo0709 opened this issue Apr 5, 2018 · 5 comments
Closed

Comments

@tokyo0709
Copy link

Adding all of our components to be able to render them server side would eventually get out of hand. There should be a way to wildcard and search subdirectories.

Example of the problem

public static class ReactConfig
{
    public static void Configure()
    {
        ReactSiteConfiguration.Configuration
            .AddScript("~/ClientApp/Components/Comments/Comment.jsx")
            .AddScript("~/ClientApp/Components/Comments/CommentBox.jsx")
            .AddScript("~/ClientApp/Components/Comments/CommentForm.jsx")
            .AddScript("~/ClientApp/Components/Comments/CommentList.jsx");
            // Additional component folders with endless amounts of component jsx files
    }
}

However this seems to be done effectively with the BabelBundle package that implements IncludeDirectory in this example. If this format could be mimicked in ReactSiteConfiguration.Configuration it should solve the issue.

Proposed Solution

public static class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        // Searches components folder for all jsx files and all subdirectories for jsx files
        bundles.Add(new BabelBundle("~/scripts/components")
            .IncludeDirectory("~/ClientApp/Components", "*.jsx", true));
    }
}
@dustinsoftware
Copy link
Member

Great idea!

@Daniel15
Copy link
Member

Daniel15 commented Apr 8, 2018

One of the issues with this is that some of the files may rely on other files being loaded in a particular order. In general it seems like a good idea, though!

@tokyo0709
Copy link
Author

@Daniel15 This may be my lack of knowledge with regards to React or too simple an example but I went ahead and tested reordering my separated component scripts to this to try to mess up the dependencies,

public static class ReactConfig
{
    public static void Configure()
    {
        ReactSiteConfiguration.Configuration
            .AddScript("~/ClientApp/Components/Comments/Comment.jsx")
            .AddScript("~/ClientApp/Components/Comments/CommentForm.jsx")
            .AddScript("~/ClientApp/Components/Comments/CommentList.jsx")
            .AddScript("~/ClientApp/Components/Comments/CommentBox.jsx");
    }
}

(I'm following the reactjs.net tutorial and updated code libraries) Where CommentBox has a CommentForm and a CommentList and CommentList has several Comment components. This shouldn't work right since the order is reversed? I ran what I had and didn't notice any issues with the reordering.

@dustinsoftware
Copy link
Member

Execution might be deferred here until all the scripts have loaded. You could test this theory by doing something like this inside of Comment.jsx

render() {
  let debugComponents = JSON.stringify([typeof CommentForm, typeof CommentList, typeof CommentBox]);

  return <span>{debugComponents}</span>;
}

Look at the server and client rendered output (you can disable script loading in your browser or use CURL to see just the server output). If you see undefined in the output at all, then the script ordering does matter.

@Yaevh
Copy link

Yaevh commented Nov 27, 2018

It's actually possible to provide a wildcard, at least for a flat directory (subdirectories have to be added manually), just that it's bugged on Windows due to conflicting directory separator between ASP.NET and Windows OS. I've submitted a fix in #631

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

No branches or pull requests

4 participants