Skip to content

Data of type 'new Map()' is not getting fetched in browser, but works fine in server side. #5545

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

Closed
yan5 opened this issue Jul 15, 2022 · 1 comment

Comments

@yan5
Copy link

yan5 commented Jul 15, 2022

Describe the bug

If we return data of type new Map() from corresponding page endpoints, the component getting rendered in browser is unable to get the data, while server side is able to get it correctly.

Reproduction

index.svelte

<script>
	export let initialData;
	let map = initialData.map;
	console.log('in index.svelte map', map);
</script>

index.js

export async function get({ params }) {
    let map = new Map();
    map.set("key", "value");
    let initialData = { "map": map }
    return {
        body: {
            initialData
        }
    };
};

Below is what we see, as you can see on server side it shows map values {'key' : 'value'}, but on the browser its empty.
Moreoever, the data type itself is changed, on server its still Map, but on browser its changed to dictionary ({}).

Screenshot from 2022-07-15 19-22-36

But if we change the type to diction in index.js as follows

export async function get({ params }) {
    let map = {};
    map["key"] = "value";
    let initialData = { "map": map }

    return {
        body: {
            initialData
        }
    }
}

then both server and browser gets the data correctly as shown below.

Screenshot from 2022-07-15 19-26-37

Logs

No response

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04 LTS 22.04 LTS (Jammy Jellyfish)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 3.03 GB / 15.42 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
    npm: 8.13.2 - ~/.nvm/versions/node/v16.15.0/bin/npm
  Browsers:
    Brave Browser: 103.1.41.96
    Chrome: 103.0.5060.114
    Firefox: 102.0.1
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.55 
    @sveltejs/kit: next => 1.0.0-next.367 
    svelte: ^3.46.0 => 3.49.0 
    vite: ^2.9.13 => 2.9.14

Severity

serious, but I can work around it

Additional Information

No response

@gtm-nayan
Copy link
Contributor

Duplicate #5358 #4944

@gtm-nayan gtm-nayan closed this as not planned Won't fix, can't repro, duplicate, stale Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants