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

[Bug]: react-router-dom cannot configure nested routers of 3 levels or more #6514

Open
nguyenbatranvan opened this issue May 11, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@nguyenbatranvan
Copy link

System Info

MacOs M1

Details

With react router dom when I configure from nesting router 2 levels or less. Everything still works normally. To my surprise, When I configured to the 3rd level, an error appeared:
image

image

I copied all the files and worked with vite, everything works fine with my current config!! Is there a problem with the router?

Reproduce link

https://github.com/nguyenbatranvan/rspack-turbo-mdf

Reproduce Steps

  1. pnpm i
  2. pnpm run remote
  3. goto http://localhost:3000/nested-1 -> Working
  4. goto http://localhost:3000/nested-1/1 -> show error above
@nguyenbatranvan nguyenbatranvan added bug Something isn't working pending triage The issue/PR is currently untouched. labels May 11, 2024
@nguyenbatranvan
Copy link
Author

The problem occurs due to the publicPath='auto' configuration. If I specify publicPath='http://localhost:3000' the problem is resolved. Is there any way to automatically get publicPath according to window.location.origin?

@nguyenbatranvan
Copy link
Author

any update this??

@LingyuCoder
Copy link
Collaborator

LingyuCoder commented May 28, 2024

I think you can set output.publicPath='/' to prevent the errors. I test it in your repro and it works well.

The runtime module of auto public path is aligned with webpack. You can see its code here. It is calculated base on document.currentScript.src.

If you want to caculate base on window.location.origin, you can try to write a plugin which uses compilation.runtimeModule hook to override the content of the runtime. Just like code below:

class Plugin {
	apply(compiler) {
		compiler.hooks.compilation.tap("MyPlugin", compilation => {
			compilation.hooks.runtimeModule.tap("MyPlugin", (module, chunk) => {
				if (module.name === "auto_public_path") {
					const originSource = module.source.source.toString("utf-8");
					module.source.source = Buffer.from(
						`/* code of your own auto public path runtime module */`,
						"utf-8"
					);
				}
			});
		});
	}
}

@LingyuCoder LingyuCoder removed the pending triage The issue/PR is currently untouched. label May 28, 2024
@nguyenbatranvan
Copy link
Author

I think you can set output.publicPath='/' to prevent the errors. I test it in your repro and it works well.

The runtime module of auto public path is aligned with webpack. You can see its code here. It is calculated base on document.currentScript.src.

If you want to caculate base on window.location.origin, you can try to write a plugin which uses compilation.runtimeModule hook to override the content of the runtime. Just like code below:

class Plugin {
	apply(compiler) {
		compiler.hooks.compilation.tap("MyPlugin", compilation => {
			compilation.hooks.runtimeModule.tap("MyPlugin", (module, chunk) => {
				if (module.name === "auto_public_path") {
					const originSource = module.source.source.toString("utf-8");
					module.source.source = Buffer.from(
						`/* code of your own auto public path runtime module */`,
						"utf-8"
					);
				}
			});
		});
	}
}

I can't seem to apply this plugin. Is there any documentation on how to write a plugin with rspack?

@LingyuCoder
Copy link
Collaborator

LingyuCoder commented May 30, 2024

I think you can set output.publicPath='/' to prevent the errors. I test it in your repro and it works well.
The runtime module of auto public path is aligned with webpack. You can see its code here. It is calculated base on document.currentScript.src.
If you want to caculate base on window.location.origin, you can try to write a plugin which uses compilation.runtimeModule hook to override the content of the runtime. Just like code below:

class Plugin {
	apply(compiler) {
		compiler.hooks.compilation.tap("MyPlugin", compilation => {
			compilation.hooks.runtimeModule.tap("MyPlugin", (module, chunk) => {
				if (module.name === "auto_public_path") {
					const originSource = module.source.source.toString("utf-8");
					module.source.source = Buffer.from(
						`/* code of your own auto public path runtime module */`,
						"utf-8"
					);
				}
			});
		});
	}
}

I can't seem to apply this plugin. Is there any documentation on how to write a plugin with rspack?

same as webpack. see this doc for more details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants