Giter Club home page Giter Club logo

Comments (10)

lilouartz avatar lilouartz commented on September 22, 2024

I can somewhat workaround this by changing my server-side object declaration to match what client renders, i.e.

{
  name: 'Hello, World!',
  '@context': 'https://schema.org',
},

But this is finicky and problematic because I have ESLint rule that auto sorts properties alphabetically.

from remix.

brophdawg11 avatar brophdawg11 commented on September 22, 2024

This looks like it's coming from internal JSON.parse behavior that must order numeric object keys:

Screenshot 2024-05-28 at 11 33 29 AM

@jacob-ebey What do you think about prefixing those with _ or something in turbo-stream to make them non-numeric?

from remix.

lilouartz avatar lilouartz commented on September 22, 2024

I think in my case it is the properties that start with @.

from remix.

brophdawg11 avatar brophdawg11 commented on September 22, 2024

It's not related to the name of the key. It's due to the reuse of a name property that was previously used. turbo-stream dedupes keys and values to keep the payload minimal, and it tracks them basically with an incrementing integer. When you return something like the following, the first occurrence of name gets assigned a lower integer than @context and then the second occurrence of name re-uses the earlier/lower id.

export const loader = () => {
  return {
    meta: [
      { 
        name: 'description', 
        // ^ `name` here gets assigned a lower numeric id since it's earlier
        content: 'Welcome to Remix!',
     },
      {
        'script:ld+json': [
          {
            '@context': 'https://schema.org',
             // ^ `@context` here gets assigned a higher numeric id since it's later
             name: 'Hello, World!',
             // ^ `name` here reuses the earlier (lower) numeric id
          },
        ],
      },
    ],
  };
};

This results in the problem I described above where we stringify an object with a higher numeric key, followed by a lower numeric key - and JSON.parse re-orders them when parsing, moving name before @context

from remix.

jacob-ebey avatar jacob-ebey commented on September 22, 2024

I believe I have addressed this with [email protected]. I can no longer reproduce it in the stackblitz: https://stackblitz.com/edit/remix-run-remix-eliwev?file=package.json

from remix.

brophdawg11 avatar brophdawg11 commented on September 22, 2024

I think the serialization is still unstable in a slightly different manner - just not surfacing this specific meta/json+ld issue. Here's a simplified repro on 2.2.3: https://stackblitz.com/edit/remix-run-remix-bbrwkg?file=app%2Froutes%2F_index.tsx

from remix.

jacob-ebey avatar jacob-ebey commented on September 22, 2024

Added some better tests and addressed it here: jacob-ebey/turbo-stream#45

from remix.

brophdawg11 avatar brophdawg11 commented on September 22, 2024

👍 Awesome - the above stackblitz is fixed with [email protected] via the solution in #9421 (comment).

from remix.

brophdawg11 avatar brophdawg11 commented on September 22, 2024

[email protected] will be the default version in Remix 2.11.2 (currently in prerelease, stable release later this week) so you won't need your own turbo-stream dependency in your package.json once upgrading 👍

from remix.

lilouartz avatar lilouartz commented on September 22, 2024

Thank you!

from remix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.