|
303 | 303 | end |
304 | 304 | end |
305 | 305 |
|
| 306 | + context "when existing RSC webpack configs have customized import anchors" do |
| 307 | + before(:all) do |
| 308 | + prepare_destination |
| 309 | + simulate_existing_rails_files(package_json: true) |
| 310 | + simulate_npm_files(package_json: true) |
| 311 | + simulate_existing_file("config/initializers/react_on_rails_pro.rb", <<~RUBY) |
| 312 | + ReactOnRailsPro.configure do |config| |
| 313 | + config.server_renderer = "NodeRenderer" |
| 314 | + end |
| 315 | + RUBY |
| 316 | + simulate_existing_file("Procfile.dev", "rails: bin/rails s\n") |
| 317 | + simulate_pro_webpack_files |
| 318 | + simulate_existing_file("config/webpack/serverWebpackConfig.js", <<~JS) |
| 319 | + const { RSCWebpackPlugin } = require('react-on-rails-rsc/WebpackPlugin'); |
| 320 | + const webpack = require('webpack'); |
| 321 | +
|
| 322 | + const configureServer = (rscBundle = false) => { |
| 323 | + const serverWebpackConfig = { plugins: [] }; |
| 324 | +
|
| 325 | + if (!rscBundle) { |
| 326 | + serverWebpackConfig.plugins.push(new RSCWebpackPlugin({ isServer: true })); |
| 327 | + } |
| 328 | +
|
| 329 | + return serverWebpackConfig; |
| 330 | + }; |
| 331 | +
|
| 332 | + module.exports = { default: configureServer }; |
| 333 | + JS |
| 334 | + simulate_existing_file("config/webpack/clientWebpackConfig.js", <<~JS) |
| 335 | + const { RSCWebpackPlugin } = require('react-on-rails-rsc/WebpackPlugin'); |
| 336 | +
|
| 337 | + const configureClient = () => { |
| 338 | + const clientConfig = { plugins: [] }; |
| 339 | + clientConfig.plugins.push(new RSCWebpackPlugin({ isServer: false })); |
| 340 | +
|
| 341 | + return clientConfig; |
| 342 | + }; |
| 343 | +
|
| 344 | + module.exports = configureClient; |
| 345 | + JS |
| 346 | + |
| 347 | + Dir.chdir(destination_root) do |
| 348 | + run_generator(["--force"]) |
| 349 | + end |
| 350 | + end |
| 351 | + |
| 352 | + it "does not add undefined rscClientReferences references" do |
| 353 | + assert_file "config/webpack/serverWebpackConfig.js" do |content| |
| 354 | + expect(content).not_to include("clientReferences: rscClientReferences") |
| 355 | + expect(content).not_to include("const rscClientReferences =") |
| 356 | + end |
| 357 | + assert_file "config/webpack/clientWebpackConfig.js" do |content| |
| 358 | + expect(content).not_to include("clientReferences: rscClientReferences") |
| 359 | + expect(content).not_to include("const rscClientReferences =") |
| 360 | + end |
| 361 | + |
| 362 | + warning_text = GeneratorMessages.messages.join("\n") |
| 363 | + expect(warning_text).to include("clientReferences option in serverWebpackConfig.js") |
| 364 | + expect(warning_text).to include("clientReferences option in clientWebpackConfig.js") |
| 365 | + end |
| 366 | + end |
| 367 | + |
306 | 368 | context "when the client webpack config uses aliased imports" do |
307 | 369 | before(:all) do |
308 | 370 | prepare_destination |
|
0 commit comments