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

Nested static aliases fail with exporting #258

Closed
wingertge opened this issue Feb 19, 2023 · 8 comments
Closed

Nested static aliases fail with exporting #258

wingertge opened this issue Feb 19, 2023 · 8 comments
Labels
C-bug Category: bug tribble-reported This issue was reported through Tribble.

Comments

@wingertge
Copy link
Contributor

This issue is reporting a bug in the code of Perseus. Details of the scope will be available in issue labels.
The author described their issue as follows:

Static aliases seem to get copied before the before_export plugin action has finished running, leading to errors when creating an alias for a generated file. The file is there in the dist/static directory after the failed export, but the export fails with a "file not found" error.

The steps to reproduce this issue are as follows:

Run an external compiler or something else that generates code in the before_export plugin step. Run perseus export.

A minimum reproducible example is available at <>.

  • Hydration-related: false
  • The author is willing to attempt a fix: false
Tribble internal data

dHJpYmJsZS1yZXBvcnRlZCxDLWJ1ZyxBLWRlcGxveW1lbnQ=

@github-actions github-actions bot added A-deployment Area: deployment C-bug Category: bug tribble-reported This issue was reported through Tribble. labels Feb 19, 2023
@arctic-hen7
Copy link
Member

Hmm, that certainly sounds like a bug introduced in the rewrite, I'll take a look...

@arctic-hen7
Copy link
Member

I've just tried this with the following code, which generates a file test.txt in the root of the project and then creates a static alias to it:

actions
    .settings_actions
    .add_static_aliases
    .register_plugin("test-plugin", |_, _| {
        let mut map = std::collections::HashMap::new();
        map.insert("/test".to_string(), "test.txt".to_string());
        Ok(map)
    });
#[cfg(engine)]
actions
    .export_actions
    .before_export
    .register_plugin("test-plugin", |_, _| {
        std::fs::write("test.txt", "Hello, world!").unwrap();
        Ok(())
    });

This seems to work fine for me, as it does when I change the path so the file is placed in dist/static (although you really shouldn't put things in there, since a user's pages could trivially override them and leave your app in a very strange state, I would strongly recommend putting them in the root of dist/, or, better, in a directory inside dist/ named according to your plugin's name).

What exactly is your problematic code, and what is the precise error you're receiving?

@wingertge
Copy link
Contributor Author

I haven't had time to properly investigate yet, I just got an issue from a user of perseus-tailwind and it didn't seem related to my code since normal builds work fine and I am hooking into before_export with the same code from build.
The code is here:
https://github.com/wingertge/perseus-tailwind/blob/master/src/lib.rs

I wait for the tailwind compiler process to exit before returning from the plugin so it should be done writing.
The output path is user defined by the way, I have no control over that. I just picked dist/static/tailwind.css as an example output path.

@arctic-hen7
Copy link
Member

Hmm, is this on the latest beta?

@wingertge
Copy link
Contributor Author

I got around to doing more testing and it seems this is some weird behaviour from Command actually. output() should wait until the process has exited, but it only prints the pre-compile message so it's clearly returning before the actual compilation is run. Closing this and investigating what could be going on.

@wingertge
Copy link
Contributor Author

wingertge commented Feb 21, 2023

After further debugging, there was an error in my code but there also still seems to be an issue with perseus itself. I fixed my issue and I'm explicitly printing out whether the file exists after I run the compile step (it does), but it still says it's not there. This is just a hunch, but this feels like a path resolution issue, where regular build and export use different resolutions.

@wingertge wingertge reopened this Feb 21, 2023
@wingertge
Copy link
Contributor Author

wingertge commented Feb 21, 2023

Ok I fixed it but this is definitely a bug. If the static alias points to /static/tailwind.css it fails, if it points to just /tailwind.css it succeeds. Something is breaking static aliases which host things at /static. The location of the file doesn't actually change anything, it's the server path that breaks it.

@arctic-hen7
Copy link
Member

arctic-hen7 commented Feb 25, 2023

This is actually a much bigger issue: any nested static aliases will fail with exporting, because the directories needed for them are not created by the CLI core!

@arctic-hen7 arctic-hen7 changed the title Export logic is being run before the before_export plugin step is finished Nested static aliases fail with exporting Feb 25, 2023
@arctic-hen7 arctic-hen7 removed the A-deployment Area: deployment label Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug tribble-reported This issue was reported through Tribble.
Projects
None yet
Development

No branches or pull requests

2 participants