remix icon indicating copy to clipboard operation
remix copied to clipboard

fix(remix-react): avoid dynamic import of relative file

Open FinPlorer opened this issue 2 years ago • 3 comments

Problem :

  • Setting a relative "publicPath" in remix.config produce error on Safari. image

Cause :

  • Relative import ignore base path in safari : https://bugs.webkit.org/show_bug.cgi?id=201692

Solution :

  • Create the full path instead of letting the "import"

I tested it successfully on safari and safari mobile.

FinPlorer avatar Jan 05 '23 15:01 FinPlorer

⚠️ No Changeset found

Latest commit: 92e0a74cc79ce37e541c7f0504e8e7e0d70d391a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Jan 05 '23 15:01 changeset-bot[bot]

Hi @MatthieuCoelho,

Welcome, and thank you for contributing to Remix!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected].

Thanks!

- The Remix team

remix-cla-bot[bot] avatar Jan 05 '23 15:01 remix-cla-bot[bot]

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

remix-cla-bot[bot] avatar Jan 05 '23 15:01 remix-cla-bot[bot]

Hi @MatthieuCoelho!

Are you still interested in getting this one merged?

If so, please rebase onto latest dev & resolve conflicts

MichaelDeBoey avatar May 02 '23 00:05 MichaelDeBoey

Hi @MatthieuCoelho!

Are you still interested in getting this one merged?

If so, please rebase onto latest dev & resolve conflicts

Yes absolutely, it should be good :)

FinPlorer avatar May 02 '23 08:05 FinPlorer

Could you provide an example application demonstrating the bug that this fixes?

brophdawg11 avatar Aug 22 '23 20:08 brophdawg11

@brophdawg11 With this change in default sandbox : In remix.config.js publicPath: "../build/",

In root.tsx <base href="/" />

If you build and start this sandbox : https://codesandbox.io/p/sandbox/quirky-frost-9h2wwv

  • Imports on chrome are working (See in developers tools)
  • But failed on safari with : [Error] Failed to load resource: the server responded with a status of 404 (Not Found) (chunk-P2YRTDNV.js, line 0), due to this import import {c as e, e as p} from "../build/_shared/chunk-P2YRTDNV.js";

FinPlorer avatar Aug 23 '23 13:08 FinPlorer

Can you explain why you need a publicPath that goes up a directory? Public paths are usually to tell the browser where to find the scripts and indicate a root level path such as /build/ (which resolves to https://{yourdomain}.com/build/) or an absolute URL such as https://cdn.example.com/ to host assets on an external CDN domain.

publicPath: "../build" seems like an odd/invalid use case to me since it sort of tells the browser to load from something like https://{yourdomain}.com/../build/ which is invalid.

Can you use a root-relative or absolute path for your juse-case?

brophdawg11 avatar Aug 28 '23 18:08 brophdawg11

We want to ‘build once, run everywhere’, since the public path is dynamically generated at runtime we can’t use root-relative or absolute paths . Using a relative path is the only way.

FinPlorer avatar Aug 29 '23 13:08 FinPlorer